Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Splitting string

From: Mukul Gandhi <mukul_gandhi@--------->
To:
Date: 8/3/2004 5:16:00 AM
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent