使用 xsl 访问 UML:xmi (xml) 中的属性

Accessing UML: attribute in xmi (xml) with xsl

我有这个 .xml (xmi) 从 whitestarUML 导出,定义了一些简单的 类:

<?xml version = "1.0" encoding = "UTF-8"?>
<?xml-stylesheet type="text/xsl" href="umlTransform.xsl"?>
<XMI xmi.version = "1.1" xmlns:UML="href://org.omg/UML/1.3" timestamp = "Fri May 03 14:36:4 2019">
<XMI.header>
  <XMI.documentation>
    <XMI.owner></XMI.owner>
    <XMI.contact></XMI.contact>
    <XMI.exporter>StarUML.XMI-Addin</XMI.exporter>
    <XMI.exporterVersion>1.0</XMI.exporterVersion>
    <XMI.notice></XMI.notice>
  </XMI.documentation>
  <XMI.metamodel xmi.name = "UML" xmi.version = "1.3"/>
 </XMI.header>
<XMI.content>
<UML:Model xmi.id="UMLProject.1">
  <UML:Namespace.ownedElement>
    <UML:Model xmi.id="UMLModel.2" name="Use Case Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Stereotype xmi.id="X.27" name="useCaseModel" extendedElement="UMLModel.2"/>
      </UML:Namespace.ownedElement>
    </UML:Model>
    <UML:Model xmi.id="UMLModel.3" name="Analysis Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Stereotype xmi.id="X.28" name="analysisModel" extendedElement="UMLModel.3"/>
      </UML:Namespace.ownedElement>
    </UML:Model>
    <UML:Model xmi.id="UMLModel.4" name="Design Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Class xmi.id="UMLClass.5" name="Vector" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.18" isActive="false">
          <UML:Classifier.feature>
            <UML:Attribute xmi.id="UMLAttribute.6" name="dimension" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
            <UML:Attribute xmi.id="UMLAttribute.7" name="values" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
            <UML:Attribute xmi.id="UMLAttribute.8" name="Iterator" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.5"/>
            <UML:Operation xmi.id="UMLOperation.9" name="push" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.5"/>
            <UML:Operation xmi.id="UMLOperation.10" name="clean" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.5"/>
            <UML:Operation xmi.id="UMLOperation.11" name="insertAt" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.5"/>
          </UML:Classifier.feature>
        </UML:Class>
        <UML:Class xmi.id="UMLClass.12" name="Iterator" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" participant="UMLAssociationEnd.17" isActive="false">
          <UML:Classifier.feature>
            <UML:Attribute xmi.id="UMLAttribute.13" name="dirPointer" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.12"/>
            <UML:Attribute xmi.id="UMLAttribute.14" name="reference" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.12"/>
            <UML:Operation xmi.id="UMLOperation.15" name="reference" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.12"/>
          </UML:Classifier.feature>
        </UML:Class>
        <UML:Association xmi.id="UMLAssociation.16" name="" visibility="public" isSpecification="false" namespace="UMLModel.4">
          <UML:Association.connection>
            <UML:AssociationEnd xmi.id="UMLAssociationEnd.17" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.16" type="UMLClass.12"/>
            <UML:AssociationEnd xmi.id="UMLAssociationEnd.18" name="" visibility="public" isSpecification="false" isNavigable="true" ordering="unordered" aggregation="none" targetScope="instance" changeability="changeable" association="UMLAssociation.16" type="UMLClass.5"/>
          </UML:Association.connection>
        </UML:Association>
        <UML:Class xmi.id="UMLClass.19" name="Sample" visibility="public" isSpecification="false" namespace="UMLModel.4" isRoot="false" isLeaf="false" isAbstract="false" isActive="false">
          <UML:Classifier.feature>
            <UML:Attribute xmi.id="UMLAttribute.20" name="var1" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.19"/>
            <UML:Attribute xmi.id="UMLAttribute.21" name="var2" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.19"/>
            <UML:Attribute xmi.id="UMLAttribute.22" name="var3" visibility="public" isSpecification="false" ownerScope="instance" changeability="changeable" targetScope="instance" type="" owner="UMLClass.19"/>
            <UML:Operation xmi.id="UMLOperation.23" name="op1" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.19"/>
            <UML:Operation xmi.id="UMLOperation.24" name="op2" visibility="public" isSpecification="false" ownerScope="instance" isQuery="false" concurrency="sequential" isRoot="false" isLeaf="false" isAbstract="false" specification="" owner="UMLClass.19"/>
          </UML:Classifier.feature>
        </UML:Class>
        <UML:Stereotype xmi.id="X.29" name="designModel" extendedElement="UMLModel.4"/>
      </UML:Namespace.ownedElement>
    </UML:Model>
    <UML:Model xmi.id="UMLModel.25" name="Implementation Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Stereotype xmi.id="X.38" name="implementationModel" extendedElement="UMLModel.25"/>
      </UML:Namespace.ownedElement>
    </UML:Model>
    <UML:Model xmi.id="UMLModel.26" name="Deployment Model" visibility="public" isSpecification="false" namespace="UMLProject.1" isRoot="false" isLeaf="false" isAbstract="false">
      <UML:Namespace.ownedElement>
        <UML:Stereotype xmi.id="X.39" name="deploymentModel" extendedElement="UMLModel.26"/>
      </UML:Namespace.ownedElement>
    </UML:Model>
  </UML:Namespace.ownedElement>
</UML:Model>
<UML:TaggedValue xmi.id="X.30" tag="ordering" value="unordered" modelElement="UMLAttribute.6"/>
<UML:TaggedValue xmi.id="X.31" tag="ordering" value="unordered" modelElement="UMLAttribute.7"/>
<UML:TaggedValue xmi.id="X.32" tag="ordering" value="unordered" modelElement="UMLAttribute.8"/>
<UML:TaggedValue xmi.id="X.33" tag="ordering" value="unordered" modelElement="UMLAttribute.13"/>
<UML:TaggedValue xmi.id="X.34" tag="ordering" value="unordered" modelElement="UMLAttribute.14"/>
<UML:TaggedValue xmi.id="X.35" tag="ordering" value="unordered" modelElement="UMLAttribute.20"/>
<UML:TaggedValue xmi.id="X.36" tag="ordering" value="unordered" modelElement="UMLAttribute.21"/>
<UML:TaggedValue xmi.id="X.37" tag="ordering" value="unordered" modelElement="UMLAttribute.22"/>
</XMI.content>
</XMI>

我正在尝试将每个 UML:Attribute 模块中的属性 "visibility" 更改为 "private"。到目前为止,我的方法是首先复制原始 .xml 的全部内容,然后特别是 select 每个 "visibility" 属性:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:UML="org.omg.xmi.namespace.UML" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="UML:Attribute/@visibility">
        <xsl:attribute name="visibility">
                <xsl:text>private</xsl:text>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

但由于模块名称中的冒号,它不起作用,所以我想知道如何访问和更改该字段。提前谢谢你。

嗯,您的样式表声明:

xmlns:UML="org.omg.xmi.namespace.UML"

而您的 XML 有:

xmlns:UML="href://org.omg/UML/1.3" 

所以你的 UML: 与他们的 UML: 不匹配,你的第二个模板从未被应用。