Question : Get item out of array

Hi,

I have a quick question regarding xslt.

This code returns my path as page node ids
<xsl:value-of select="$currentPage/@path"/>
in the format
-1,1240,1530,1974,2291,2716

How can return 1 specific value? eg the 3rd one form the left?

Thanks.

Answer : Get item out of array

If you can't do this using XSLT2, you will need a recursive function,
see below example

don't hesitate to ask for an explanation, if you need one
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
    <xsl:template match="currentPage">
        <xsl:call-template name="get-item-from-array">
            <xsl:with-param name="str" select="@path"/>
            <xsl:with-param name="item-no" select="3"/>
            <xsl:with-param name="seperator" select="','"/>
        </xsl:call-template>
    </xsl:template>
    <xsl:template name="get-item-from-array">
        <xsl:param name="str"/>
        <xsl:param name="item-no"/>
        <xsl:param name="seperator"/>
        <xsl:choose>
            <xsl:when test="$item-no &lt;= 1">
                <xsl:value-of select="substring-before($str, $seperator)"/>
            </xsl:when>
            <xsl:otherwise>
                <xsl:call-template name="get-item-from-array">
                    <xsl:with-param name="str" select="substring-after($str, $seperator)"/>
                    <xsl:with-param name="item-no" select="$item-no - 1"/>
                    <xsl:with-param name="seperator" select="$seperator"/>
                </xsl:call-template>
            </xsl:otherwise>
        </xsl:choose>
        
    </xsl:template>
</xsl:stylesheet>
Random Solutions  
 
programming4us programming4us