You can have as many when
elements as you like inside the choose
:
<xsl:choose>
<xsl:when test="@personas < 5">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="@personas <= 10">
<xsl:text>2</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>3</xsl:text>
</xsl:otherwise>
</xsl:choose>
A choose
takes the first matching when
branch, so you don't need to check for >=5
in the second branch - you already know this because you didn't take the first one.
But for future reference, a more idiomatic XSLT way to approach this might be to use matching templates instead of a choose
construct:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- copy everything unchanged except when overridden -->
<xsl:template match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()"/></xsl:copy>
</xsl:template>
<xsl:template match="@personas[. < 5]" priority="10">
<xsl:attribute name="categoria">1</xsl:attribute>
</xsl:template>
<xsl:template match="@personas[. <= 10]" priority="9">
<xsl:attribute name="categoria">2</xsl:attribute>
</xsl:template>
<xsl:template match="@personas" priority="8">
<xsl:attribute name="categoria">3</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
Here we need the explicit priorities because the patterns @personas[. < 5]
and @personas[. <= 10]
are considered equally specific by default.