通过另一个获取属性值

时间:2015-05-14 17:10:12

标签: xml xslt xpath

我试图从不同的标签中获取属性值。 这是我的xml文件:

<XMI xmi.version='1.2' timestamp='Fri Apr 24 12:24:29 WAT 2015' xmlns:UML='omg.org/UML/1.4'>
<XMI.header>
    <XMI.documentation>
        <XMI.exporter>MagicDraw UML</XMI.exporter>
        <XMI.exporterVersion>9.0</XMI.exporterVersion>
    </XMI.documentation>
    <XMI.metamodel xmi.name='UML' xmi.version='1.4'/>
</XMI.header>
<XMI.content>
    <UML:Model xmi.id='eee_1045467100313_135436_1' name='Data'>
        <UML:Namespace.ownedElement>
            <UML:Package xmi.id='_9_0_1abc0480_1360417290093_794953_110' name='hr'>
                                <UML:Namespace.ownedElement>
                                    <UML:Class xmi.id='_9_0_1abc0480_1360417356156_809319_114' name='Employee'>
                                        <UML:ModelElement.stereotype>
                                            <UML:Stereotype href='newModel.xml|egiva_1022741650486_759581_123'>
                                                <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                    <referentPath xmi.value='Data types::entity'/>
                                                </XMI.extension>
                                            </UML:Stereotype>
                                        </UML:ModelElement.stereotype>
                                        <UML:Namespace.ownedElement>
                                            <UML:Abstraction xmi.id='_9_0_1abc0480_1360417353312_416353_113' client='_9_0_1abc0480_1360417356156_809319_114'>
                                                <UML:ModelElement.stereotype>
                                                    <UML:Stereotype href='newModel.xml|_9_0_897027e_1105630590734_613299_511'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='Data types::realize'/>
                                                        </XMI.extension>
                                                    </UML:Stereotype>
                                                </UML:ModelElement.stereotype>
                                                <UML:Dependency.supplier>
                                                    <UML:ModelElement href='newModel.xml|osama_1059572400642_541580_122'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::AbstractValue'/>
                                                        </XMI.extension>
                                                    </UML:ModelElement>
                                                </UML:Dependency.supplier>
                                            </UML:Abstraction>
                                        </UML:Namespace.ownedElement>
                                        <UML:Classifier.feature>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417405078_72412_147' name='identifier'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_448855_210'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_577212_211' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:ModelElement.stereotype>
                                                    <UML:Stereotype href='newModel.xml|_5f701fc_1096291047273_745359_1547'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='Data types::code'/>
                                                        </XMI.extension>
                                                    </UML:Stereotype>
                                                    <UML:Stereotype href='newModel.xml|_5f701fc_1096282286643_472107_1342'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='Data types::sequence'/>
                                                        </XMI.extension>
                                                    </UML:Stereotype>
                                                </UML:ModelElement.stereotype>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_303948_819'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::LongValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417733453_835499_209' name='nationalNumber'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_891620_212'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_892394_213' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:ModelElement.stereotype>
                                                    <UML:Stereotype href='newModel.xml|_5f701fc_1096291083287_539898_1561'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='Data types::unique'/>
                                                        </XMI.extension>
                                                    </UML:Stereotype>
                                                </UML:ModelElement.stereotype>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_303948_819'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::LongValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417420906_228687_149' name='firstName'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_425799_214'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_373524_215' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_67517_836'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::StringValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417434156_213690_151' name='lastName'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_611745_216'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_180814_217' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_67517_836'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::StringValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417449984_748333_153' name='birthDate'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_837478_218'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_515637_219' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|5f701fc_1081944857059_464638_0'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::BusinessDate'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417653468_896023_199' name='age'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_747933_220'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_274122_221' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_716005_817'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::IntegerValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417667046_866560_201' name='address'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_142919_222'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_940840_223' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|osama_1057833941718_811415_136'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::TextValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417684531_808413_203' name='phoneNumber'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418132359_292342_291'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418132359_144507_292' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|ahmad_1057828584656_67517_836'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::StringValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417699265_17119_205' name='contractStartDate'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_343557_226'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_361878_227' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|5f701fc_1081944857059_464638_0'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::BusinessDate'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417718562_213156_207' name='contractEndDate'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360417783468_929078_228'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360417783468_350602_229' lower='0' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier href='newModel.xml|5f701fc_1081944857059_464638_0'>
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::arch::basicStruct::data::BusinessDate'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417795250_360778_246' name='civilState' type='_9_0_1abc0480_1360417555656_961843_176'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418132359_514503_293'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418132359_191202_294' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417815687_976484_248' name='numberOfChildren'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418132359_201182_295'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418132359_799315_296' lower='0' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier >
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::IntegerValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                            <UML:Attribute xmi.id='_9_0_1abc0480_1360417865968_440560_250' name='salary'>
                                                <UML:StructuralFeature.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418132359_655101_297'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418132359_229798_298' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:StructuralFeature.multiplicity>
                                                <UML:StructuralFeature.type>
                                                    <UML:Classifier >
                                                        <XMI.extension xmi.extender='MagicDraw UML 9.0' xmi.extenderID='MagicDraw UML 9.0'>
                                                            <referentPath xmi.value='com::new::arch::basicStruct::data::DoubleValue'/>
                                                        </XMI.extension>
                                                    </UML:Classifier>
                                                </UML:StructuralFeature.type>
                                            </UML:Attribute>
                                        </UML:Classifier.feature>
                                    </UML:Class>
                                    <UML:Association xmi.id='_9_0_1abc0480_1360418146656_245894_318'>
                                        <UML:Association.connection>
                                            <UML:AssociationEnd xmi.id='_9_0_1abc0480_1360418146656_962005_316' isNavigable='true' aggregation='aggregate' participant='_9_0_1abc0480_1360417356156_809319_114'>
                                                <UML:AssociationEnd.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418222968_828268_417'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418222968_333793_418' lower='0' upper='-1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:AssociationEnd.multiplicity>
                                            </UML:AssociationEnd>
                                            <UML:AssociationEnd xmi.id='_9_0_1abc0480_1360418146656_839833_317' isNavigable='true' participant='_9_0_1abc0480_1360417892796_581831_252'>
                                                <UML:AssociationEnd.multiplicity>
                                                    <UML:Multiplicity xmi.id='_9_0_1abc0480_1360418222968_561784_419'>
                                                        <UML:Multiplicity.range>
                                                            <UML:MultiplicityRange xmi.id='_9_0_1abc0480_1360418222968_684290_420' lower='1' upper='1'/>
                                                        </UML:Multiplicity.range>
                                                    </UML:Multiplicity>
                                                </UML:AssociationEnd.multiplicity>
                                            </UML:AssociationEnd>
                                        </UML:Association.connection>
                                    </UML:Association
                                </UML:Namespace.ownedElement>
            </UML:Package>
        </UML:Namespace.ownedElement>
    </UML:Model>
   </XMI.content>
 </XMI>

我想从<UML:Class>的属性参与者中提取标记<UML:Association>的属性名称的值。 这是我在XSLT文件中所做的:

<xsl:stylesheet xmlns:UML='omg.org/UML/1.4' xmlns:xmi="http://www.omg.org/XMI"
xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:palmyraUMLprofile="http:///schemas/palmyraUMLprofile/_oXvaUNuaEeCgfpbtt2dTfQ/5"
xmlns:fn="http://www.w3.org/2005/xpath-functions" version="1.0">
<xsl:output indent="yes" method="xml" />
<xsl:strip-space elements="*" />
<xsl:template match="UML:Class">
    <packagedElement>
        <xsl:attribute name="xmi:type">uml:Class</xsl:attribute>
        <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
        <xsl:attribute name="name">
            <xsl:value-of select="@name" />
          </xsl:attribute>
        <generalization>
            <xsl:attribute name="xmi:id">
              <xsl:value-of select="generate-id()" />
            </xsl:attribute>
            <general xmi:type="uml:Class" />
        </generalization>
        <xsl:for-each select="//UML:Association/UML:Association.connection/UML:AssociationEnd/@aggregation='composite'">

        </xsl:for-each>
        <xsl:for-each select="UML:Classifier.feature/UML:Attribute">
            <ownedAttribute>
                <xsl:attribute name="xmi:id">
                                    <xsl:value-of select="@xmi.id" />
                                </xsl:attribute>
                <xsl:attribute name="name">
                                    <xsl:value-of select="@name" />
                                </xsl:attribute>
                <xsl:attribute name="isUnique">false</xsl:attribute>
                <xsl:variable name="hreff">
                    <xsl:call-template name="replace_palmyra">
                        <xsl:with-param name="text"
                            select="UML:StructuralFeature.type/UML:Classifier/@href" />
                        <xsl:with-param name="replace" select="'PalmyraModel.xml|'" />
                        <xsl:with-param name="by"
                            select="'platform:/plugin/PalmyraUmlProfile/PalmyraModel/PalmyraModel.uml#'" />
                    </xsl:call-template>
                </xsl:variable>
                <type xmi:type="uml:Class" href="{$hreff}" />

                <xsl:choose>
                    <xsl:when
                        test="UML:StructuralFeature.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower !=''">
                        <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}"
                            value="{UML:StructuralFeature.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                    </xsl:when>
                    <xsl:otherwise>
                        <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}" />
                    </xsl:otherwise>
                </xsl:choose>
            </ownedAttribute>
        </xsl:for-each>
    </packagedElement>
    <xsl:apply-templates />
</xsl:template>
<xsl:template match="UML:Association">
    <xsl:choose>
        <xsl:when test="UML:Association.connection/UML:AssociationEnd/@aggregation='composite'">
            <packagedElement>
                <xsl:attribute name="xmi:type">uml:Association</xsl:attribute>
                <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                <xsl:attribute name="name">compositon</xsl:attribute>
                <xsl:variable name="member1" select="concat(generate-id(),'a1')" />
                <xsl:variable name="member2" select="concat(generate-id(),'a2')" />

                <xsl:attribute name="memberEnd">
            <xsl:value-of select="concat($member1,' ',$member2)" />
          </xsl:attribute>
                <ownedEnd>
                    <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <!--<xsl:variable name="name-association1"> <xsl:value-of select="UML:Association.connection/UML:AssociationEnd[1]/@participant" 
                        /> <xsl:value-of select="*/UML:Class[@id='UML:Association.connection/UML:AssociationEnd[1]/@participant']/@name"/> 
                        </xsl:variable> -->
                    <xsl:attribute name="name">
            <xsl:value-of select="hello" />
          </xsl:attribute>
                    <xsl:attribute name="type">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <xsl:attribute name="isUnique">false</xsl:attribute>
                    <xsl:attribute name="name">
            <xsl:value-of select="association" />
          </xsl:attribute>
                    <upperValue xmi:type="uml:LiteralUnlimitedNatural"
                        xmi:id="{concat(generate-id(),'id1')}"
                        value="{UML:Association.connection/UML:AssociationEnd/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@upper}" />
                    <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{concat(generate-id(),'id2')}"
                        value="{UML:Association.connection/UML:AssociationEnd/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                </ownedEnd>
            </packagedElement>
        </xsl:when>
        <xsl:when
            test="UML:Association.connection/UML:AssociationEnd/@aggregation='aggregate'">
            <packagedElement>
                <xsl:attribute name="xmi:type">uml:Association</xsl:attribute>
                <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                <xsl:attribute name="name">aggregation</xsl:attribute>
                <xsl:variable name="member1" select="concat(generate-id(),'a1')" />
                <xsl:variable name="member2" select="concat(generate-id(),'a2')" />
                <xsl:variable name="id1"
                    select="UML:Association.connection/UML:AssociationEnd[1]/@participant" />
                <xsl:variable name="id2"
                    select="UML:Association.connection/UML:AssociationEnd[2]/@participant" />
                <xsl:attribute name="memberEnd">
            <xsl:value-of select="concat($member1,' ',$member2)" />
          </xsl:attribute>
                <ownedEnd>
                    <xsl:attribute name="xmi:id">
            <xsl:value-of select="$member1" />
          </xsl:attribute>
                    <xsl:attribute name="name">
            <xsl:value-ofselect="//UML:Class[@xmi.id='UML:Association.connection/UML:AssociationEnd/@participant']/@name" />
</xsl:attribute>" />
          </xsl:attribute>
                    <xsl:attribute name="type">
            <xsl:value-of
                        select="UML:Association.connection/UML:AssociationEnd[1]/@participant" />
          </xsl:attribute>
                    <xsl:attribute name="isUnique">false</xsl:attribute>
                    <xsl:attribute name="association">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <upperValue xmi:type="uml:LiteralUnlimitedNatural"
                        xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[1]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@upper}" />
                    <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[1]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                </ownedEnd>
                <ownedEnd>
                    <xsl:attribute name="xmi:id">
            <xsl:value-of select="$member2" />
          </xsl:attribute>
                    <xsl:attribute name="name">
            <xsl:value-of select="hello" />
          </xsl:attribute>
                    <xsl:attribute name="type">
            <xsl:value-of
                        select="UML:Association.connection/UML:AssociationEnd[2]/@participant" />
          </xsl:attribute>
                    <xsl:attribute name="isUnique">false</xsl:attribute>
                    <xsl:attribute name="association">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <upperValue xmi:type="uml:LiteralUnlimitedNatural"
                        xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[2]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@upper}" />
                    <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[2]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                </ownedEnd>
            </packagedElement>
        </xsl:when>
        <xsl:when
            test="UML:Association.connection/UML:AssociationEnd[not(@aggregation)]">
            <packagedElement>
                <xsl:attribute name="xmi:type">association</xsl:attribute>
                <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                <xsl:attribute name="name">
            <xsl:value-of select="association" />
          </xsl:attribute>
                <xsl:variable name="member1" select="concat(generate-id(),'a1')" />
                <xsl:variable name="member2" select="concat(generate-id(),'a2')" />

                <xsl:attribute name="memberEnd">
            <xsl:value-of select="concat($member1,' ',$member2)" />
                                </xsl:attribute>
                <ownedEnd>
                    <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <xsl:attribute name="name">
            <xsl:value-of select="Hello" />
          </xsl:attribute>
                    <xsl:attribute name="type">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <xsl:attribute name="isUnique">false</xsl:attribute>
                    <xsl:attribute name="association">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <upperValue xmi:type="uml:LiteralUnlimitedNatural"
                        xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[1]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@upper}" />
                    <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[1]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                </ownedEnd>
                <ownedEnd>
                    <xsl:attribute name="xmi:id">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <xsl:attribute name="name">

            <xsl:value-of select="UML:Class[@id='']" />
          </xsl:attribute>
                    <xsl:attribute name="type">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <xsl:attribute name="isUnique">false</xsl:attribute>
                    <xsl:attribute name="association">
            <xsl:value-of select="@xmi.id" />
          </xsl:attribute>
                    <upperValue xmi:type="uml:LiteralUnlimitedNatural"
                        xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[2]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@upper}" />
                    <lowerValue xmi:type="uml:LiteralInteger" xmi:id="{generate-id()}"
                        value="{UML:Association.connection/UML:AssociationEnd[2]/UML:AssociationEnd.multiplicity/UML:Multiplicity/UML:Multiplicity.range/UML:MultiplicityRange/@lower}" />
                </ownedEnd>
            </packagedElement>
        </xsl:when>
    </xsl:choose>
    <xsl:apply-templates />
  </xsl:template>
</xsl:stylesheet>

1 个答案:

答案 0 :(得分:1)

如果您在样式表的根级别声明此<xsl:key>

<xsl:key name="UMLClasses" match="UML:Class" use="@xmi.id" />

然后您可以检索类名(UML:Class/@name),这要归功于以下说明:

 <xsl:value-of select="key('UMLClasses', UML:Association.connection/UML:AssociationEnd/@participant)/@name" />

例如,这就是我得到的结果:

<ownedEnd xmi:id="d1e155a1"
             name="Employee"
             type="_9_0_1abc0480_1360417356156_809319_114"
             isUnique="false"
             association="_9_0_1abc0480_1360418146656_245894_318">
      <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="d1e155" value="-1"/>
      <lowerValue xmi:type="uml:LiteralInteger" xmi:id="d1e155" value="0"/>
   </ownedEnd>

但是,可能存在问题,因为UML:Association.connection/UML:AssociationEnd可能会检索多个节点(<Association.connection>可能有多个<AssociationEnd>)。如果第一个 AssociationEnd 总是正确的,那么这对你有好处。如果没有,您可能需要根据您的要求进行适当的选择。