0
votes

I want to select attribute of element but I know that he hasn´t other different attribute. For clarification, if element hasn´t attribute "receive Event" I want to select attribute xmi:id.

This is my xml input:


    <packagedElement xmi:type="uml:Package" xmi:id="EAPK_2A526457_CD3B_48f1_8A97_63CD2A91C147" name="loopSequence" visibility="public">
                <packagedElement xmi:type="uml:Collaboration" xmi:id="EAID_CB000000_457_CD3B_48f1_8A97_63CD2A91C14" name="EA_Collaboration1" visibility="public">
                    <ownedBehavior xmi:type="uml:Interaction" xmi:id="EAID_IN000000_457_CD3B_48f1_8A97_63CD2A91C14" name="EA_Interaction1" visibility="public">
                        <message xmi:type="uml:Message" xmi:id="EAID_A42D4D8F_EFB6_4b4e_A861_1FEE1946B30D" name="selectDrivingSchool" messageKind="found" messageSort="synchCall" receiveEvent="EAID_FR000000_F30E_4171_884F_3A3DFE7EB88F"/>
                        <message xmi:type="uml:Message" xmi:id="EAID_67E4B669_8E61_4571_AD23_245CC7F62F4C" name="getCourse" messageKind="complete" messageSort="synchCall" sendEvent="EAID_FR000001_F30E_4171_884F_3A3DFE7EB88F" receiveEvent="EAID_FR000001_07E9_42c1_AFDB_1285EC859B12"/>
                        <message xmi:type="uml:Message" xmi:id="EAID_4B784479_1F3B_425c_A286_B5F0D75E1832" name="selectCourse" messageKind="complete" messageSort="synchCall" sendEvent="EAID_FR000000_07E9_42c1_AFDB_1285EC859B12" receiveEvent="EAID_FR000001_7564_47cf_9C22_DF3A6E7302AD"/>
                        <message xmi:type="uml:Message" xmi:id="EAID_6C98A08D_1BD1_42bf_9662_59F6FE2E4442" name="end" messageKind="lost" messageSort="synchCall" sendEvent="EAID_FR000000_7564_47cf_9C22_DF3A6E7302AD"/>
                    </ownedBehavior>
                </packagedElement>
                <packagedElement xmi:type="uml:Class" xmi:id="EAID_B6F68D66_8F02_4d02_91B5_2BD7B1742A51" name="Activity Final" visibility="public"/>
                <packagedElement xmi:type="uml:Class" xmi:id="EAID_CAFE5DAF_4C2B_47e5_8704_B4A5D3528513" name="Activity Initial" visibility="public"/>
    </packagedElement>

This is my XSLT code:

 <xsl:template  match="packagedElement[@xmi:type='uml:Class' and @name='ActivityFinal' or @name='Activity Final']">
        <node xmi:type="uml:ActivityFinalNode" xmi:id= "EAID_ACTIVITY{substring(@xmi:id,14,28)}" name="{@name}" visibility="{@visibility}">
            <incoming xmi:idref=""/>
        </node>
 </xsl:template>

And output XML should like that:

<node xmi:type="uml:ActivityFinalNode" xmi:id="EAID_ACTIVITY_8F02_4d02_91B5_2BD7B1742A51" name="Activity Final" visibility="public">
    <incoming xmi:idref="EAID_6C98A08D_1BD1_42bf_9662_59F6FE2E4442"/>
</node>

So I need to get xmi:id of the 4th message which has not attribute "receiveEvent". Maybe I should use xsl:key, but with match messages???

1

1 Answers

1
votes

The not() function can do that. Wrapped for legibility:

<xsl:template match="packagedElement[
    @xmi:type='uml:Class' 
    and (
        @name='ActivityFinal'
        or @name='Activity Final'
    )
]">
    <node
        xmi:type="uml:ActivityFinalNode"
        xmi:id="EAID_ACTIVITY{substring(@xmi:id, 14, 28)}"
        name="{@name}"
        visibility="{@visibility}"
    >
        <incoming xmi:idref="{.//message[not(@receiveEvent)]/@xmi:id}" />
    </node>
</xsl:template>

Notes:

  • this will output the xmi:id of the first <message> that has no receiveEvent attribute. If multiple such messages can exist, you need to define the behavior or the template accordingly.
  • It's better to put parenthesis around the or part of your match expression.