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

Re: XSL Word-counter

Subject: Re: XSL Word-counter
From: Steve Tinney <stinney@xxxxxxxxxxxxx>
Date: Thu, 10 Feb 2000 10:56:22 -0500
xsl param counter
Steve Tinney wrote:
> allowed myself to use node-set in implementing it, but I daresay it
> could be done without even in a single script.

I shouldn't have started myself off.   Here's another version which is
leaner, meaner, pure XSL, and comes with no more guarantees than the
last one, i.e., none.

wc.xsl:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template name="word-count">
  <xsl:param name="in" select="."/>
  <xsl:call-template name="words-in-text">
    <xsl:with-param name="texts" select="$in//text()"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="words-in-text">
  <xsl:param name="texts"/>
  <xsl:param name="words" select="''"/>
  <xsl:param name="total" select="0"/>
  <xsl:choose>
    <xsl:when test="string-length($words) > 0">
      <xsl:call-template name="words-in-text">
        <xsl:with-param name="texts" select="$texts"/>
        <xsl:with-param name="words" 
          select="substring-after($words,' ')"/>
        <xsl:with-param name="total" select="$total+1"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:when test="count($texts) > 0">
      <xsl:call-template name="words-in-text">
        <xsl:with-param name="texts" 
          select="$texts[position() > 1]"/>
        <xsl:with-param name="words"
          select="normalize-space($texts[1])"/>
        <xsl:with-param name="total" select="$total"/>
      </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="$total"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>


 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.