Assume I have variables $a, $b, $c and $d which all hold numbers. I would like to get the smallest (largest) value. My typical XSLT 1.0 approach to this is
<xsl:variable name="minimum">
<xsl:for-each select="$a | $b | $c | $d">
<xsl:sort
select="."
data-type="number"
order="ascending" />
<xsl:if test="position()=1"><xsl:value-of select="." /></xsl:if>
</xsl:for-each>
</xsl:variable>
However, my xslt 1.0 processor complains with
runtime error: file stylesheet.xslt line 106 element for-each
The ‘select’ expression does not evaluate to a node set.
How can I compute the minimum (maximum) of the given values?
Of course, I could use a long series of <xsl:when> statements and check all combinations, but I’d rather like a smaller solution.
If the variables have statically defined values (not dynamically computed), then something like the following can be done with XSLT 1.0:
When this transformation is applied on any XML document (not used), the wanted, correct result is produced:
II. Now, suppose the variables are dynamically defined.
We can do something like this (but need the
xxx:node-set()extension function):when this transformation is applied on the following XML document:
the wanted, correct result is produced: