This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: string split
- To: xsl-list at mulberrytech dot com
- Subject: Re: string split
- From: Tobias dot Grundmann at ofd dot mf dot lsa-net dot de (Tobias Grundmann)
- Date: Tue, 19 Sep 2000 16:47:50 +0200
- Organization: OFD Magdeburg
- References: <9B66BBD37D5DD411B8CE00508B69700F03C182@pborolocal.rnib.org.uk>
- Reply-To: xsl-list at mulberrytech dot com
why do you try to "build up the answer"? Does the following script work for
you?
Regards
Tobias
<xsl:template match="/">
<xsl:call-template name="links">
<xsl:with-param name="str" select="'1,2,3'"/>
</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>
"Pawson, David" schrieb:
> Given
> <doc>
> <elem>5,6,7</elem>
> </doc>
>
> I need an output of
>
> <a href="#id5">5</a> <a href="#id6">6</a> <a
> href="#id7">7</a>
>
> 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