Reputation: 13
For an input as below:
<Classes>
<ClassOfService Cabin="Y" Status="6">S</ClassOfService>
<ClassOfService Cabin="Y" Status="5">N</ClassOfService>
<ClassOfService Cabin="Y" Status="1">Q</ClassOfService>
<ClassOfService Cabin="Y" Status="0">O</ClassOfService>
<ClassOfService Cabin="Y" Status="0">E</ClassOfService>
</Classes>
I want to get the first, in order of bottom to top, ClassOfService value which has stauts >=3. So it should be N. I tried following in my xsl but it doesn’t work:
<xsl:variable name="qualifiedClass" select="Classes/ClassOfService[@Status >=3]"/>
<xsl:variable name="numOfqClass" select="count(Classes/ClassOfService[@Status >=3])"/>
<xsl:value-of select="$qualifiedClass/ClassOfService[$numOfqClass]"/>
how to select an element from variable?
Alternatively, I also tried below, doesn't work either.
<xsl:value-of select="Classes/ClassOfService[@Status>=3][last()]"/>
Upvotes: 1
Views: 49
Reputation: 116959
I want to get the first, in order of bottom to top, ClassOfService value which has stauts >=3.
I think that "first, in order of bottom to top" means last, in document order (which is the order by which XPath operates).
So your attempt:
<xsl:value-of select="Classes/ClassOfService[@Status >= 3][last()]"/>
is the correct answer, and it does work if applied from the context of the /
root node.
See it working here: http://xsltransform.net/3NSSEuN
Upvotes: 1