Subject: Re: [xsl] splitting a string at , From: "M. David Peterson" <m.david@xxxxxxxxxx> Date: Wed, 14 Jan 2004 16:41:04 -0700 |
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: [xsl] 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] splitting a string at ,, Lars Huttar | Thread | [xsl] Re: splitting a string at ,, Dimitre Novatchev |
RE: [xsl] splitting a string at ,, Lars Huttar | Date | RE: [xsl] splitting a string at ,, Ryan Graham |
Month |