I need to add CSS classes to each item output by an XSLT template. The class values need to include the position of the node, which is fine, but the position needs to be written in words (classOne, classTwo etc) rather than a digits (class1, class2 etc).
The code I have almost works. It outputs the position correctly as a number, but when I use that position to return the written version of the number it just picks the first one every time, so I always get a class of ‘classOne’. If I hard-code the number it works fine.
<xsl:param name="currentPage"/>
<xsl:variable name="numbers" select="my.library:Split('One,Two,Three,Four,Five,Six,Seven,Eight',',')"/>
<xsl:template match="/">
<xsl:apply-templates select="$currentPage/*[starts-with(name(), 'largeImage')]" mode="large" />
</xsl:template>
<xsl:template match="*" mode="large">
<xsl:variable name="index" select="substring(name(), 11)"/>
<div class="class{$numbers/*[$index]}">item</div>
</xsl:template>
Can anyone see how I can get it to convert the $index value into the written equivalent?
Use
<div class="class{$numbers/*[position() = $index]}">item</div>. If that does not work then you need to show details of what kind of data your my.library:Split function returns.