xsl-list
[Top] [All Lists]

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

2006-10-06 03:31:13
On 10/6/06, Robert Walpole <robert(_dot_)walpole(_at_)devon(_dot_)gov(_dot_)uk> 
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>