This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: string split
For
<doc>
<elem>5,6,7</elem>
</doc>
I have the following
=======================
<xsl:template match="/">
<xsl:apply-templates select="/doc/elem"/>
</xsl:template>
<xsl:template match="elem">
<xsl:param name="csv" select="."/>
<xsl:variable name="wlist"
select="concat(normalize-space(translate($csv,',',' ')),' ')"/>
<xsl:variable name="first">
<xsl:if test="$csv!=' '">
<xsl:value-of select="substring-before($wlist, ' ')"/>
</xsl:if>
</xsl:variable>
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat('#id',$first)" />
</xsl:attribute>
<xsl:value-of select="$first" />
</a>
<xsl:text disable-output-escaping="yes"><![CDATA[ ]]></xsl:text>
<xsl:variable name="rest" select="substring-after($wlist, ' ')"/>
<xsl:if test="$rest">
<xsl:apply-templates select=".">
<xsl:with-param name="csv" select="$rest"/>
</xsl:apply-templates>
</xsl:if>
</xsl:template>
=======================
Producing
<a href="#id5">5</a> <a href="#id6">6</a> <a
href="#id7">7</a>
There is probably a leaner way. Anyone?
-- Mike Berrow
-- Lexica
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list