In my xsl, I want to match
on several nodes and then grab the value of the matched node into a variable. How can I do that?
I need to place a wildcard variable in place of Budget0
below:
<xsl:template match="FieldRef[@Name='Budget0' or @Name='Scope' or @Name='Risk' or @Name='Schedule']" mode="body">
<xsl:param name="thisNode" select="."/>
<xsl:variable name="currentValue" select="$thisNode/Budget0" />
<xsl:variable name="statusRating1">(1)</xsl:variable>
<xsl:variable name="statusRating2">(2)</xsl:variable>
<xsl:variable name="statusRating3">(3)</xsl:variable>
<xsl:choose>
<xsl:when test="contains($currentValue, $statusRating1)">
<span class="statusRatingX statusRating1"></span>
</xsl:when>
<xsl:when test="contains($currentValue, $statusRating2)">
<span class="statusRatingX statusRating2"></span>
</xsl:when>
<xsl:when test="contains($currentValue, $statusRating3)">
<span class="statusRatingX statusRating3"></span>
</xsl:when>
<xsl:otherwise>
<span class="statusRatingN"><xsl:value-of select="$currentValue" /></span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
In this snippet, the xsl:template match...
works just fine; it does seem to match those fields. I can see in Firebug that those fields receive the statusRating1
css class just like they should (since they are all set to receive the value of the Budget0
field.
[update]
I found that if I use this for the variable:
<xsl:variable name="currentValue" select="current()/@Name" />
or
<xsl:variable name="currentValue" select="FieldRef[@Name=current()/@Name"] />
It will get caught in the otherwise
tag, and will print the name of the field. In other words, the html prints
<span class="statusRatingN">Budget0</span>
If I try any of Dimitre's solutions (below), it never matches in any of the when
clauses, and the html is outputted like this (notice the span's text is blank):
<span class="statusRatingN"></span>
Therefore, I deduce that the $currentValue
is only getting the name of the attribute, it isn't referring to value of the node. I need to refer to the value of that particular node.