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

RE: string split

Subject: RE: string split
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Tue, 19 Sep 2000 15:01:18 +0100
xsl string split
Dave,
Try
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">


<xsl:template match="elem">
	<xsl:call-template name="links">
          	<xsl:with-param name="str" select="."/>
	</xsl:call-template>
</xsl:template>
<xsl:template name="links">
	<xsl:param name="str"/>

  	<xsl:choose>
    	<xsl:when test="contains($str,',')">
		<a href="#id{substring-before($str,',')}"><xsl:value-of
select="substring-before($str,',')"/></a>
      		<xsl:call-template name="links">
          		<xsl:with-param name="str" select="substring-after($str,',')" />
          	</xsl:call-template>
   	</xsl:when>
        <xsl:otherwise>
        	<a href="#id{$str}"><xsl:value-of select="$str"/></a>
        </xsl:otherwise>
      	</xsl:choose>
</xsl:template>
</xsl:stylesheet>

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


>Given
><doc>
><elem>5,6,7</elem>
></doc>
>
>I need an output of
>
><a href="#id5">5</a>&nbsp;<a href="#id6">6</a>&nbsp;<a
>href="#id7">7</a>&nbsp;
>
>I think its a recursive call to a string splitter template.
>I cant figure out how to 'build up the answer'
>
>template (non worker) is
>
> <xsl:template name="links">
>    <xsl:param name="str"/>
>  <xsl:param name="res"/>
>
>
>  <xsl:choose>
>    <xsl:when test="contains($str,',')">
>      <xsl:call-template name="links">
>          <xsl:with-param name="str" select="substring-after($str,',')"/>
>          <xsl:with-param name="res"><xsl:value-of select="$res"/>
>            <a href="#id{substring-before($str,',')}"><xsl:value-of
>select="substring-before($str,',')"/></a></xsl:with-param>
>          </xsl:call-template>
>        </xsl:when>
>        <xsl:otherwise>
>
>          <xsl:value-of select="$res"/>
>        </xsl:otherwise>
>      </xsl:choose>
>  </xsl:template>
>
>Called using
>
>  <xsl:call-template name="links">
>          <xsl:with-param name="str" select="."/>
>          <xsl:with-param name="res" select="''"/>
>        </xsl:call-template>
>
>Where . contains 5,6,7 as a string.
>
>Any help appreciated.
>DaveP
>
>
> 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.