How do I print out the attribute values of all message and lifeline nodes at once?
By “at once”, I mean while printing out a message name, I need to access the lifeline nodes. The only attributes I am concerned about are: lifeline/@name, and message/@name. I am trying to print out the message names, with the lifeline name that the message moves from. You do not have to post an answer to solve how I will associate the message with its start and end lifelines. That’s tricky. I just need to know how to access the lifeline and message attribute values at once. Or if its even possible. The XSLT shows the output format.
For the following XML , just focus on the lifeline, message, and packagedElement nodes. For context, the XML is of a UML model with a sequence diagram. Preserving the order of the sequence messages is not necessary. I am developing on the client side, thus the stylesheet href line is included in the XML. I can’t change the XML beyond the stylesheet href. All of the needed namespaces are included. I am transforming XML to text. I want to print out these values as tab delimited text.
XML:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="multiple nonthreaded iers.xsl" type="text/xsl"?>
<uml:Model xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML" xmi:id="idModel" name="main">
<packagedElement xmi:type="uml:Package" xmi:id="idPackage" name="ThreadedIERPackage">
<packagedElement xmi:type="uml:Collaboration" xmi:id="idCollaboration" name="ThreadedIERCollaboration">
<ownedBehavior xmi:type="uml:Interaction" xmi:id="idInteraction">
<lifeline xmi:type="uml:Lifeline" xmi:id="_OccJQguaEeGMo_zLRqy_vg" name="Lifeline1"/>
<lifeline xmi:type="uml:Lifeline" xmi:id="_Oo87QguaEeGMo_zLRqy_vg" name="Lifeline2" coveredBy="_QrWQ2AuaEeGMo_zLRqy_vg _R4-hlQuaEeGMo_zLRqy_vg _QrWQ0guaEeGMo_zLRqy_vg"/><!-- can ignore the last id -->
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_R4-hlQuaEeGMo_zLRqy_vg" name="MessageOccurrenceSpecification2" covered="_Oo87QguaEeGMo_zLRqy_vg" event="_R4-hlguaEeGMo_zLRqy_vg" message="_R4-hlwuaEeGMo_zLRqy_vg"/>
<fragment xmi:type="uml:MessageOccurrenceSpecification" xmi:id="_QrWQ2AuaEeGMo_zLRqy_vg" name="MessageOccurrenceSpecification1" covered="_Oo87QguaEeGMo_zLRqy_vg" event="_QrWQ2QuaEeGMo_zLRqy_vg" message="_QrWQ2guaEeGMo_zLRqy_vg"/>
<fragment xmi:type="uml:BehaviorExecutionSpecification" xmi:id="_QrWQ0guaEeGMo_zLRqy_vg" name="BehaviorExecutionSpecification1" covered="_Oo87QguaEeGMo_zLRqy_vg" start="_QrWQ2AuaEeGMo_zLRqy_vg" finish="_R4-hlQuaEeGMo_zLRqy_vg"/>
<message xmi:type="uml:Message" xmi:id="_QrWQ2guaEeGMo_zLRqy_vg" name="Message1" receiveEvent="_QrWQ2AuaEeGMo_zLRqy_vg"/>
<message xmi:type="uml:Message" xmi:id="_R4-hlwuaEeGMo_zLRqy_vg" name="Message2" messageSort="reply" sendEvent="_R4-hlQuaEeGMo_zLRqy_vg"/>
</ownedBehavior>
</packagedElement>
<packagedElement xmi:type="uml:CallEvent" xmi:id="_QrWQ2QuaEeGMo_zLRqy_vg" name="CallEvent1"/>
<packagedElement xmi:type="uml:CallEvent" xmi:id="_R4-hlguaEeGMo_zLRqy_vg" name="CallEvent2"/>
</packagedElement>
<profileApplication xmi:type="uml:ProfileApplication" xmi:id="idProfileApplication">
<eAnnotations xmi:type="ecore:EAnnotation" xmi:id="idProfileAnnotation" source="http://www.eclipse.org/uml2/2.0.0/UML">
<references xmi:type="ecore:EPackage" href="pathmap://SysMLActivityExtensionsProfile.uml#ProfileContentId"/>
</eAnnotations>
<appliedProfile xmi:type="uml:Profile" href="pathmap://SysMLActivityExtensionsProfile.uml#ActivityProfileId"/>
</profileApplication>
</uml:Model>
XSLT:
<xsl:template match="/">
<xsl:text>#Sending Lifeline (Producer)</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Receiving Lifeline (Consumers)</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>Name(s)</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:text>ID</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:value-of select="$newline"/>
<xsl:apply-templates />
</xsl:template>
<xsl:template match="packagedElement/ownedBehavior">
<xsl:for-each select="lifeline"><!-- prints all lifelines-->
<xsl:value-of select="@name"/><xsl:text>.OE</xsl:text>
<xsl:value-of select="$tab"/>
</xsl:for-each>
<xsl:text>OE --> OE</xsl:text>
<xsl:value-of select="$tab"/>
<xsl:value-of select="message/@name"/>
<xsl:value-of select="$tab"/>
</xsl:template>
</xsl:stylesheet>
What I have tried:
I have created a packagedElement/ownedBehavior template to access both nodes (lifeline, message), since they’re both children. However, it doesn’t print out all of the messages or lifelines unless I use a for -each. But, if I use a for-each, then I can only access messages or lifelines, not both.
I have tried using multiple templates, i.e. one for lifeline, and another for message. Example: <xsl:template match="lifeline">. Of course, I can’t access both nodes’ attributes at once. Even, if I use the call template function. I have tried it and it failed.
This is a tricky one, so I appreciate your response.
In general, use the union operator —
|— to select both types of elements in one template:Or:
Alternatively, iterate over one or the other, associating as you go. Example:
…where
<some_condition_here>is a predicate selecting the associated node.