|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: append values to a String
Hi Dongzhi,
> I'd like to loop through all the children nodes under <Sample>,
Looping is easiest with <xsl:for-each>:
<xsl:for-each select="Sample/*">
...
</xsl:for-each>
> find those have non-empty value,
Filter the elements that you've selected using a predicate that tests
whether they have a string value:
<xsl:for-each select="Sample/*[string()]">
...
</xsl:for-each>
> 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,".
The <xsl:value-of> gets the string value of the element; add the comma
using <xsl:text>.
<xsl:for-each select="Sample/*[string()]">
<xsl:value-of select="." />
<xsl:text>,</xsl:text>
</xsl:for-each>
> And I need to assign this String to a variable since I need to use
> it elsewhere.
Just wrap the above in an <xsl:variable> element as follows:
<xsl:variable name="String">
<xsl:for-each select="Sample/*[string()]">
<xsl:value-of select="." />
<xsl:text>,</xsl:text>
</xsl:for-each>
</xsl:variable>
Technically, the $String variable is set to a result tree fragment
containing a single text node whose string value is the value that
you're after, but this will make no difference when you use the
variable as you would a string.
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








