tags:

views:

112

answers:

2

hi All

i need to loop through all the nodes in the xml document and append the values with comma ( , ) finally after the last element i should not have commma (,)

can any body help me.

thanking you, Ramana kumar.

+4  A: 

You can do something like this:

<xsl:for-each select="element">
    <xsl:value-of select="whatever" />
    <xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>

The position() function returns the index of the current element in the for-each context, and last() returns the index of the last element.

The Conditional Processing with xsl:if section of the XSLT documentation provides more information about this example.

Greg Hewgill
+3  A: 

In XSLT 2.0 you can use the string-join function.

<xsl:value-of  select="string-join(/element/whatever, ',')"/>
Mads Hansen
i want to know, wether XSLT 2.0 is supported in .net 3.5
Ramana kumar
.NET does not have native XSLT 2.0 support, but Saxon is an option for .NET 2.0 or later: http://saxon.sourceforge.net/
Mads Hansen