Доступ к UML: атрибут в xmi (xml) с помощью xsl - PullRequest
0 голосов
/ 05 мая 2019

У меня есть .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: Атрибут модуль для «частного».Пока что мой подход заключается в том, чтобы сначала скопировать все содержимое исходного XML-файла, а затем выбрать каждый атрибут «видимость»:

<?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>

Но это не работает из-за двоеточия в имени модуля, поэтому ябыло интересно, как получить доступ и изменить это поле.Заранее спасибо.

1 Ответ

1 голос
/ 05 мая 2019

Итак, ваша таблица стилей объявляет:

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

, в то время как ваш XML имеет:

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

, поэтому ваш UML: не соответствует их UML:, а ваш второй шаблон никогда не будетприложенное.

...