Struggling to use XSLT apply-templates versus call-template and foreach

24 views
Skip to first unread message

loll...@googlemail.com

unread,
Apr 28, 2013, 10:46:30 AM4/28/13
to xs...@googlegroups.com
Hi,

I am rewriting one of my XSLT template to get it more structured and avoid using xsl:for-each as best. Trying to translate an XMI UML model I get into trouble accessing a kind of nodes from within another node while that node I am are was from a apply-templates fragment.

While I can properly handle UML:Attribute nodes to create my columns when I am in a UML:Class node, I cannot access the UML:AssociationEnd/UML:AssociationEnd.participant/@xmi.idref value because it is not located within the current UML:Class element.

How do I restructure the XMI document to get the matching association into the UML:Classifier.feature node and then apply a different template in that case?

I am using libXML2 and for my tests xsltproc.

Here is a sample snipped of my XMI document with a comment:

            <UML:Class xmi.id = 'BOUML_0x19b1d30' name = 'CD' visibility = 'public'
              isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false'
              isActive = 'false'>
              <UML:Classifier.feature>
                <UML:Attribute xmi.id = 'BOUML_0x19b1a60' name = 'Titel' visibility = 'private'
                  isSpecification = 'false' ownerScope = 'instance'>
                  <UML:StructuralFeature.type>
                    <UML:DataType xmi.idref = 'BOUML_datatype_0'/>
                  </UML:StructuralFeature.type>
                </UML:Attribute>
                <UML:Attribute xmi.id = 'BOUML_0x19b19b0' name = 'Laenge' visibility = 'private'
                  isSpecification = 'false' ownerScope = 'instance'>
                  <UML:StructuralFeature.type>
                    <UML:DataType xmi.idref = 'BOUML_datatype_1'/>
                  </UML:StructuralFeature.type>
                </UML:Attribute>

I want to include a column with the ClassName of the referenced class from the UML:AssociationEnd.participant element, such as it would look like I have an attribute, but I haven't.
Thus I must react on the UML:AssociationEnd.participant in question in two different ways. Can I use xsl:copy-of to hook the correct Association node into the UML:Class node?
 
                <UML:Association xmi.id = 'BOUML_0x19b1780' name = '(Titel)' isSpecification = 'false' isRoot = 'false' isLeaf = 'false' isAbstract = 'false'>
                    ...
                </UML:Association>

                <UML:Attribute xmi.id = 'BOUML_0x19b1840' name = 'ReleaseDatum' visibility = 'private'
                  isSpecification = 'false' ownerScope = 'instance'>
                  <UML:StructuralFeature.type>
                    <UML:DataType xmi.idref = 'BOUML_datatype_2'/>
                  </UML:StructuralFeature.type>
                </UML:Attribute>
              </UML:Classifier.feature>
            </UML:Class>
            <UML:Association xmi.id = 'BOUML_0x19b1780' name = '(Titel)' isSpecification = 'false'
              isRoot = 'false' isLeaf = 'false' isAbstract = 'false'>
              <UML:Association.connection>
                <UML:AssociationEnd xmi.id = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A63'
                  name = '' visibility = 'private' isSpecification = 'false' isNavigable = 'true'
                  aggregation = 'none'>
                  <UML:ModelElement.stereotype>
                    <UML:Stereotype xmi.idref = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A61'/>
                  </UML:ModelElement.stereotype>
                  <UML:ModelElement.taggedValue>
                    <UML:TaggedValue xmi.id = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A62'
                      isSpecification = 'false'/>
                  </UML:ModelElement.taggedValue>
                  <UML:AssociationEnd.participant>
                    <UML:Class xmi.idref = 'BOUML_0x19b1b50'/>
                  </UML:AssociationEnd.participant>
                </UML:AssociationEnd>
                <UML:AssociationEnd xmi.id = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A66'
                  name = '' visibility = 'private' isSpecification = 'false' isNavigable = 'true'
                  aggregation = 'aggregate'>
                  <UML:ModelElement.stereotype>
                    <UML:Stereotype xmi.idref = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A64'/>
                  </UML:ModelElement.stereotype>
                  <UML:ModelElement.taggedValue>
                    <UML:TaggedValue xmi.id = '-64--88--106-30-186617fb:13e4f65dd21:-8000:0000000000000A65'
                      isSpecification = 'false'/>
                  </UML:ModelElement.taggedValue>
                  <UML:AssociationEnd.participant>
                    <UML:Class xmi.idref = 'BOUML_0x19b1d30'/>
                  </UML:AssociationEnd.participant>
                </UML:AssociationEnd>
              </UML:Association.connection>
            </UML:Association>


The template that handles the class, fails using xsl:value-of:

<xsl:variable name="AssocuationID">
<!-- What I do within Helper.Lookup.Association -->
<xsl:value-of select="//UML:Class[@xmi.idref=$ClassID]/../../../../@xmi.id"/>
<!--
<xsl:call-template name="Helper.Lookup.Association">
<xsl:with-param name="ClassID" select="$ClassID"/>
<xsl:with-param name="Aggregate" select="'none'"/>
</xsl:call-template>
-->
</xsl:variable>

Any help?

Thanks,

Lothar

BTW, Google topic editor on my Mac is very bad. Every time I type, the edit window gets smaller in height :-)

loll...@googlemail.com

unread,
Apr 29, 2013, 2:16:26 AM4/29/13
to xs...@googlegroups.com
Hi,

I have missed the namespace declarations within my imported XSLT templates. (xmlns:UML="org.omg.xmi.namespace.UML" exclude-result-prefixes="UML")

With them I was able to do simple xsl:value-of select="" stuff to resolve the referenced classes.

Thanks,

Lothar
Reply all
Reply to author
Forward
0 new messages