I have a problem with XSLT/XPath when parsing my UML file (XMI).
The following expressions behave differently ($thisId contains the xmi:id of the class to check whether it is enhanced by the stereotype 'revisioned' inside 'itechnical_Profile'):
1)
<xsl:value-of select="//*:revisioned[@base_Class = $thisId]/@xmi:id"/>
gives me correct id '_16_5_1_29f0058e_1359051179028_158208_16339application2'.
2)
<xsl:value-of select="//itechnical_Profile:revisioned[@base_Class = $thisId]/@xmi:id"/>
gives me no output at all.
3)
<xsl:value-of select="/xmi:XMI/*:revisioned[@base_Class = $thisId]/@xmi:id"/>
gives me correct id '_16_5_1_29f0058e_1359051179028_158208_16339application2'.
I have checked with
<xsl:value-of select="name(/xmi:XMI/*:revisioned[@base_Class = $thisId])"/>
that the node is named 'itechnical_Profile:revisioned'.
I have also checked with
<xsl:value-of select="name(/xmi:XMI/*:revisioned[@base_Class = $thisId]/..)"/>
that the parent node is named 'xmi:XMI'.
So why does 2) fail?
With the stereotype 'UML_Standard_Profile:entity' it works flawlessly.
Is my understanding of '//' wrong?
Thanks in advance!
Shortening the XMI file would be quite some work ... so after some debugging I have come up with the following workaround:
<xsl:function name="itechnical_uml:enhancedByStereotype_revisioned" as="xs:boolean">
<xsl:param name="packagedElementNode" as="element()"/>
<xsl:variable name="elementName" select="local-name($packagedElementNode)"/>
<xsl:if test="($elementName != 'packagedElement')">
<xsl:message terminate="yes">
Error: this is not a packagedElement!
</xsl:message>
</xsl:if>
<xsl:if test="($packagedElementNode/@xmi:type != 'uml:Class')">
<xsl:message terminate="yes">
<xsl:text>Error: this is a packagedElement but not with xmi:type = 'uml:Class'!
</xsl:text>
</xsl:message>
</xsl:if>
<xsl:variable name="thisId" select="$packagedElementNode/@xmi:id"/>
<xsl:variable name="stereotypeID">
<xsl:value-of select="root($packagedElementNode)//stereotype[@name = 'itechnical_Profile:revisioned']/@stereotypeID"/>
</xsl:variable>
<xsl:if test="$stereotypeID = ''">
<xsl:message terminate="yes">
<xsl:text>Error: unable to find xmi:id of stereotype 'itechnical_Profile:revisioned'!
</xsl:text>
</xsl:message>
</xsl:if>
<xsl:variable name="resultSet" as="element()*" select="root($packagedElementNode)/xmi:XMI/*:revisioned[@base_Class = $thisId]"/>
<xsl:choose>
<xsl:when test="$resultSet/@xmi:id != ''">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:function>
Checking the 'xmlns:itechnical_Profile' definitions inside UML XMI and my XSLT scripts did not show up any problems.