Re: string split

Subject: Re: string split
From: Mike Berrow <mberrow@xxxxxxxxxx>
Date: Tue, 19 Sep 2000 08:06:32 -0700
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[&nbsp;]]></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>&nbsp;<a href="#id6">6</a>&nbsp;<a
href="#id7">7</a>&nbsp;

There is probably a leaner way. Anyone?

-- Mike Berrow
-- Lexica




 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread