[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] working out where the last() is


Subject: Re: [xsl] working out where the last() is
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Fri, 6 Oct 2006 11:30:51 +0100

On 10/6/06, Robert Walpole <robert.walpole@xxxxxxxxxxxx> wrote:
Hi,

I have some XML data which contains an areaserved node as follows:

<areaserved>
        <district name="South Hams">
                <town name="Dartmouth">
                        <settlement name="Kingswear"/>
                </town>
                <town name="Totnes"/>
        </district>
        <district name="Torbay"/>
</areaserved>

I am trying to write some XSLT to transform this to a list as follows:

Kingswear, Totnes, Torbay

In 2.0 you can use:


string-join(//*[not(*)]/@name, ', ')

In 1.0 you don't have the string-join() function so you need to add
the comma yourself:

<xsl:for-each select="//*[not(*)]/@name">
	<xsl:value-of select="."/>
	<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>

cheers
andrew


Current Thread
Keywords