[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: splitting a string at ,

Subject: RE: splitting a string at ,
From: Ryan Graham <Ryan.Graham@xxxxxxxxxxxxx>
Date: Wed, 14 Jan 2004 16:46:17 -0700
string at
>I have a string seperated with commas. I am trying to
>split the string at commas.
>
>How can this be done.

I know this is not the most elegant solution, but it works:

Given this source XML-

<doc>
	<foo>split,this,string,please</foo>
</doc>

This stylesheet snippet...

<xsl:template match="foo">
	<xsl:call-template name="splitString">
		<xsl:with-param name="string1" select="."/>
	</xsl:call-template>
</xsl:template>
	
<xsl:template name="splitString">
	<xsl:param name="string1"/>
	<xsl:choose>
		<xsl:when test="contains($string1,',')">
			<xsl:variable name="beforeComma"
select="substring-before($string1,',')"/>
			<xsl:element name="entry"><xsl:value-of
select="$beforeComma"/></xsl:element>
			<xsl:variable name="afterComma"
select="substring-after($string1,',')"/>
			<xsl:call-template name="splitString">
				<xsl:with-param name="string1"
select="$afterComma" />
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:element name="entry">
				<xsl:value-of select="$string1"/>
			</xsl:element>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

...produces the following output:

<entry>split</entry>
<entry>this</entry>
<entry>string</entry>
<entry>please</entry>


Of course you can modify this to suit your personal requirements.

HTH,
RG


>Thanks
>Archana

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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.