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

Re: comma separated data

Subject: Re: comma separated data
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 6 Apr 2000 13:51:55 -0600 (MDT)
xsl comma separated
> I need to separate the following data into separate fields:
>  
> <years  title = "year">1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
> 2003,   </year>
>  
> For instance, the output needs to read:
>  
> <tr><td>1994</td><td>1995</td><td>1996</td> ... etc ... </tr>
>  
> I have seen this done using MS IE 5.0 and the DOM, but was wondering if it
> was possible using *just* XSL?

Of course.

<xsl:template match="years">
  <tr>
    <xsl:call-template name="split_years">
      <xsl:with-param name="year_list" select="text()"/>
    </xsl:call-template>
  </tr>
</xsl:template>

<xsl:template name="split_years">
  <xsl:param name="year_list"/>
  <xsl:choose>
    <!-- if there's a comma, take everything before it... -->
    <xsl:when test="contains($year_list,',')">
      <xsl:variable name="year" select="normalize-space(substring-before($year_list,','))"/>
      <!-- only make a table cell if there is non-whitespace before the comma -->
      <xsl:if test="$year">
        <td>
          <xsl:value-of select="$year"/>
        </td>
      </xsl:if>
      <!-- ...then go process everything after it -->
      <xsl:call-template name="split_years">
        <xsl:with-param name="year_list" select="substring-after($year_list,',')"/>
      </xsl:call-template>
    </xsl:when>
    <!-- if there's no comma, but something besides whitespace -->
    <xsl:when test="normalize-space($year_list)">
      <td><xsl:value-of select="$year_list"/></td>
    </xsl:when>
    <!-- otherwise, $year_list must be empty, so do nothing-->
  </xsl:choose>
</xsl:template>


 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.