RE: [xsl] append values to a String

Subject: RE: [xsl] append values to a String
From: "XSLList" <xsllist@xxxxxxxxxxxxx>
Date: Thu, 13 Feb 2003 12:08:57 -0500
Here's another variation, the only difference being the use
of normalize-space() to eliminate "empty" elements like <K1>  </K1>

There've been a couple of good posts comparing the different methods of
testing elements.  (Now if I could just figure out the syntax of axes...)

--Jeff

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl='http://www.w3.org/1999/XSL/Transform' >
<xsl:output method="xml" indent="yes"/>
	<xsl:template match="Sample">
		<xsl:variable name="csvlist">
			<xsl:for-each select="child::*[normalize-space()]">
				<xsl:value-of select="."/>
				<xsl:if test="position() != last()">
					<xsl:text>,</xsl:text>
				</xsl:if>
			</xsl:for-each>
		</xsl:variable>
	</xsl:template>
</xsl:stylesheet>

>Here's the xml:
>
><Sample>
>	<K1/>
>	<K2>something</K2>
>	<K3>something else</K3>
>	<K4/>
></Sample>
>
>I'd like to loop through all the children nodes under
><Sample>, find those
>have non-empty value, and construct a String with all those
>values append to
>each other with a "," delimiter in between them, i.e. the result String
>should look like:  "something,something else,".  And I need to
>assign this
>String to a variable since I need to use it elsewhere.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread