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

Re: Splitting string

Subject: Re: Splitting string
From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx>
Date: Mon, 2 Aug 2004 22:15:13 -0700 (PDT)
splitting string in xsl
Hi Rui,
  Please try this XSL. It uses a recursive template.

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
 
<xsl:output method="text" /> 
 
<xsl:template match="/root"> 
   <xsl:call-template name="tokenise">
     <xsl:with-param name="str" select="string" />
     <xsl:with-param name="delim" select="'/'" />
     <xsl:with-param name="prev" select="''" />
   </xsl:call-template>
</xsl:template>
 
<xsl:template name="tokenise">
   <xsl:param name="str" />
   <xsl:param name="delim" />
   <xsl:param name="prev" />
   
   <xsl:choose>
     <xsl:when
test="substring-after(substring-after($str,$delim),$delim)
!= ''">
       <xsl:value-of select="$prev" /><xsl:value-of
select="$delim" /><xsl:value-of
select="substring-before(substring-after($str,$delim),$delim)"
/>
       <xsl:text>&#xA;</xsl:text>
       <xsl:call-template name="tokenise">
         <xsl:with-param name="str"
select="concat($delim,substring-after(substring-after($str,$delim),$delim))"
/>
         <xsl:with-param name="delim" select="$delim"
/>     
         <xsl:with-param name="prev"
select="concat($prev,$delim,substring-before(substring-after($str,$delim),$delim))"
/>
       </xsl:call-template>
     </xsl:when>
     <xsl:when
test="substring-after(substring-after($str,$delim),$delim)
= ''">
       <xsl:value-of select="$prev" /><xsl:value-of
select="$str" />
     </xsl:when>
   </xsl:choose>  
</xsl:template>
  
</xsl:stylesheet>

for e.g. when it is applied to XML
<?xml version="1.0"?>
<root>
  <string>/this/is/a/test</string>
</root>

it produces output -
/this
/this/is
/this/is/a
/this/is/a/test

Regards,
Mukul

--- "Rui Alberto L. Gongalves"
<rui-l-goncalves@xxxxxxxxxxxxx> wrote:

> Hi all, 
> I have a string like:
> /this/is/a/test
> 
> and I need to create a template that will output:
> /this
> /this/is
> /this/is/a
> /this/is/a/test
> 
> I think this is not so simple as it looks at first
> glance.
> Does anyone have an idea how to solve this problem?
> Thanks for any help.
> 
> Rui
> -- 
> Rui Alberto L. Gongalves
> <rui-l-goncalves@xxxxxxxxxxxxx>
> PT Inovagco



		
__________________________________
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

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.