[xquery-talk] XSL Question

Raffaele Sena raff at aromatic.org
Tue May 23 21:47:05 PDT 2006


since you posted this on the xquery forum I am assuming you are talking 
about XPath 2.0 functionalities.

With XPath 2.0 you can use the fn:tokenize() function to split your 
comma-separated list:

	fn:tokenize(//child, ',')

returns
	('name1', 'name2_pewe', 'name3')

If you want to be XSLT 1.0 - XPath 1.0 compliant you can write a 
recursive function that uses fn:substring-before and fn:substring-after:

<xsl:template name="split">
   <xsl:param name="input-string"/>
   <xsl:param name="separator"/>

   <xsl:if test="$input-string">
     <td><xsl:value-of
        select="substring-before($input-string, $separator)/></td>
     <xsl:call-template name="split">
       <xsl:with-param name="input-string"
         select="substring-after($input-string, $separator"/>
       <xsl:with-parma name="separator" select="$separator"/>
   </xsl:if>
</xsl:template>

(I didn't really try this but it should be "almost" correct :)

-- Raffaele


Rajashekaraiah, Rashmi (HP-IT) wrote:
> Hi :
>  
> I have a XML which looks like :
> <root><child>name1,name2_pewe,name3</child></root>
>  
>  
> I want to write an xsl to trasnform this to html which should look like
> <html>
> <body>
> <table>
> <tr><td>name1<td><td></td><td></td><tr>
> </table>
> <body>
> </html>
>  
> I dono how to write a split function in xslt. please help
>  
> Thanks,
> Rashmi
>  
> !DSPAM:4473c46a146357962374464!
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> talk at xquery.com
> http://xquery.com/mailman/listinfo/talk
> 
> !DSPAM:4473c46a146357962374464!


More information about the talk mailing list