xsl:variable contains nodeset. How to output nth node of variable?
        Posted  
        
            by dnagirl
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by dnagirl
        
        
        
        Published on 2010-05-07T18:50:02Z
        Indexed on 
            2010/05/07
            19:48 UTC
        
        
        Read the original article
        Hit count: 347
        
I am transforming an XML document.  There is an attribute @prettydate that is a string similar to "Friday, May 7, 2010".  I want to split that string and add links to the month and the year. I am using the exslt:strings module and I can add any other necessary EXSLT module.
This is my code so far:
<xsl:template match="//calendar">
    <xsl:variable name="prettyparts">
        <xsl:value-of select="str:split(@prettydate,', ')"/>
    </xsl:variable>
    <table class='day'>
        <thead>
            <caption><xsl:value-of select="$prettyparts[1]"/>, 
                    <a>
                        <xsl:attribute name='href'><xsl:value-of select="$baseref"/>?date=<xsl:value-of select="@highlight"/>&per=m</xsl:attribute>
                        <xsl:value-of select='$prettyparts[2]'/>
                    </a> 
                    <xsl:value-of select='$prettyparts[3]'/>,  
                    <a>
                        <xsl:attribute name='href'><xsl:value-of select="$baseref"/>?date=<xsl:value-of select="@highlight"/>&per=y</xsl:attribute>
                        <xsl:value-of select='$prettyparts[4]'/>
                    </a> 
            </caption>
<!--etcetera-->
I have verified, by running $prettyparts through a <xml:for-each/> that I am getting the expected nodeset:
<token>Friday</token>
<token>May</token>
<token>7</token>
<token>2010</token>
But no matter which way I attempt to refer to a particular <token> directly (not in a foreach) I get nothing or various errors to do with invalid types.  Here's some of the syntax I've tried:
<xsl:value-of select="$prettyparts[2]"/>
<xsl:value-of select="$prettyparts/token[2]"/>
<xsl:value-of select="exsl:node-set($prettyparts/token[2])"/>
<xsl:value-of select="exsl:node-set($prettyparts/token)[2]"/>
Any idea what the expression ought to be?
© Stack Overflow or respective owner