Greetings,
I have a question regarding the evaluation of an expression for the xsl:choose instruction. Here is a sample snippet that will help me explain:
Code:
<xsl:template match="Entity">
<xsl:choose>
<xsl:when test="@Attrib">
<xsl:call-template name="do-something">
</xsl:call-template>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="@Attrib2='Value2'">
<xsl:call-template name="do-something-else">
</xsl:call-template>
<xsl:apply-templates/>
</xsl:when>
<xsl:when test="@Attrib3='Value3'">
<xsl:call-template name="do-something-completely-different">
</xsl:call-template>
<xsl:apply-templates/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
I suppose the question has to do with how the conditional expression is evaluated. The first "xsl:when" is always getting executed in my implementation. Even when the 'Attrib' attribute does not exist for the given node.
In my xml file the first node to evaluate has a attibute of 'Attrib2' with a value of 'Value2'. Therefore only the second 'xsl:when' above should evaluate. The test for the first xsl:when above is checking merely for the existence of a 'Attrib' attribute. (This is very similar to the bottom of page 237 in the XSLT 2.0 Programmers Reference book.)
When I move the first xsl:when down after the Attrib2 and Attrib3 tests, all seems to work correctly. As this branch will be executed much more frequently than the others (yet, hot for the first few nodes) I wanted it placed above the other tests.
Am I missing something here with regards to the way I am testing the attributes?
Thanks in advance for any assistance.
Dan