[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: "M. David Peterson" <m.david@xxxxxxxxxx>
Date: Wed, 14 Jan 2004 16:41:04 -0700
string split by delimiter xml
The following XSLT gives you what you want...

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">


<xsl:variable name="string_Comma_Delimited">a, b, c, d, e, f,
g</xsl:variable>

<xsl:template match="/">
 <table>
 <xsl:call-template name="parseString">
  <xsl:with-param name="list" select="$string_Comma_Delimited"/>
 </xsl:call-template>
 </table>
</xsl:template>

<xsl:template name="parseString">
<xsl:param name="list"/>

<xsl:if test="contains($list, ',')">
 <tr>
  <td><xsl:value-of select="substring-before($list, ',')"/></td>
 </tr>
 <xsl:call-template name="parseString">
  <xsl:with-param name="list" select="substring-after($list, ', ')"/>
 </xsl:call-template>
</xsl:if>

</xsl:template>

The preceding gives you the result:

<table>
  <tr>
    <td>a</td>
  </tr>
  <tr>
    <td>b</td>
  </tr>
  <tr>
    <td>c</td>
  </tr>
  <tr>
    <td>d</td>
  </tr>
  <tr>
    <td>e</td>
  </tr>
  <tr>
    <td>f</td>
  </tr>
</table>

Keep in mind that if there is not a space after each comma delimiter then
you will need to remove the space from the substring-after function like so:

substring-after($list, ',')

Best regards,

M.

----- Original Message ----- 
From: "Archana Rao" <archana_heroor@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, January 14, 2004 2:59 PM
Subject:  splitting a string at ,


> I have a string seperated with commas. I am trying to
> split the string at commas.
>
> How can this be done.
>
> Thanks
> Archana
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
> http://hotjobs.sweepstakes.yahoo.com/signingbonus
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.