I want to get the code for the medias
node with the lowest index. The source XML looks similar to this:
<item>
<medias>
<index>999997</index>
<code>0001</code>
</medias>
<medias>
<index>1</index>
<code>0002</code>
</medias>
<medias>
<index>999998</index>
<code>0003</code>
</medias>
<medias>
<index>999999</index>
<code>0004</code>
</medias>
</item>
In my XSLT I tried this:
<xsl:variable name="minIndex" select="math:min(item/medias/index)" />
<xsl:value-of select="item/medias[index=$minIndex]/code" />
But for some reason, the minIndex
variable does not get the lowest value of all values, but simply the value of the first node, in this case 999997
.
When sorting the nodes though, the values are ordered correctly:
<xsl:for-each select="item/medias">
<xsl:sort select="index" />
<xsl:value-of select="." /><xsl:text>,</xsl:text>
</xsl:for-each>
This outputs:
1,999997,999998,999999
Is there something else I have to take care for when using math:min
? I also tried adding /text()
to the end of my selection (after index
), but that didn't work either.
EDIT: I'm constructing my XSL transformer in Java using simply this code and giving it the XSLT file as the source:
Transformer transformer = TransformerFactory.newInstance().newTransformer(xsltSource);