Esta solución XSLT 1.0 utiliza plantillas recursivas para analizar una lista delimitada de valores para devolver el valor mínimo/máximo de la lista.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="a" select="'3'"/>
<xsl:variable name="b" select="'1'"/>
<xsl:variable name="c" select="'9'"/>
<xsl:variable name="d" select="'5'"/>
<xsl:template match="/">
<xsl:text>
Smallest: </xsl:text>
<xsl:call-template name="min">
<xsl:with-param name="values" select="concat($a,',',$b,',',$c,',',$d)"/>
</xsl:call-template>
<xsl:text>
Largest: </xsl:text>
<xsl:call-template name="max">
<xsl:with-param name="values" select="concat($a,',',$b,',',$c,',',$d)"/>
</xsl:call-template>
</xsl:template>
<xsl:template name="min">
<xsl:param name="values" />
<xsl:param name="delimiter" select="','"/>
<xsl:param name="min"/>
<xsl:variable name="currentValue" >
<xsl:choose>
<xsl:when test="contains($values, $delimiter)">
<xsl:value-of select="substring-before($values,$delimiter)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$values"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="minimumValue">
<xsl:choose>
<xsl:when test="$min and $min > $currentValue">
<xsl:value-of select="$currentValue"/>
</xsl:when>
<xsl:when test="$min">
<xsl:value-of select="$min"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentValue" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="substring-after($values,$delimiter)">
<xsl:call-template name="min">
<xsl:with-param name="min" select="$minimumValue" />
<xsl:with-param name="values" select="substring-after($values,$delimiter)" />
<xsl:with-param name="delimiter" select="$delimiter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$minimumValue" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="max">
<xsl:param name="values" />
<xsl:param name="delimiter" select="','"/>
<xsl:param name="max"/>
<xsl:variable name="currentValue" >
<xsl:choose>
<xsl:when test="contains($values, $delimiter)">
<xsl:value-of select="substring-before($values,$delimiter)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$values"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="maximumValue">
<xsl:choose>
<xsl:when test="$max and $currentValue > $max">
<xsl:value-of select="$currentValue"/>
</xsl:when>
<xsl:when test="$max">
<xsl:value-of select="$max"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$currentValue" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="substring-after($values,$delimiter)">
<xsl:call-template name="max">
<xsl:with-param name="max" select="$maximumValue" />
<xsl:with-param name="values" select="substring-after($values,$delimiter)" />
<xsl:with-param name="delimiter" select="$delimiter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$maximumValue" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Cuando se ejecuta, produce el siguiente resultado:
Smallest: 1
Largest: 9
El principal problema, pienso, es que los números no son nodos. – cHao
Creo que el problema principal es que en XSLT 1.0, la expresión en 'select' debe evaluar a un conjunto de nodos. (http://www.w3.org/TR/xslt#for-each) –