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

RE: Collect word count with xslt2.0 on saxon 8

Subject: RE: Collect word count with xslt2.0 on saxon 8
From: "Karen McAdams" <kamcadam@xxxxxxxxx>
Date: Wed, 17 May 2006 13:02:20 -0700
RE:  Collect word count with xslt2.0 on saxon 8
Hi George-

Thanks for the code sample. I would like to better understand how this
apply-templates works-
   <xsl:template match="*[contains(@class, 'topic/topic')]"
     mode="getText"/>
       <xsl:apply-templates mode="getText" select="node()"/>

It seems that the template rule would remove the node from the source at the
processing context yet with the apply templates it actually retrieves it-
could you elaborate on this approach - I also need to remove from the node
comment elements  before I count the text contents of the node -

If I add an template
<xsl:template match="draft-comment"  mode="getText"/>

I get  -
BUILD FAILED
java.lang.StackOverflowError

( I am building with Ant but this is an xsl related error . )

Karen

------------------------------

Date: Tue, 16 May 2006 10:04:22 +0300
To:  xsl-list@xxxxxxxxxxxxxxxxxxxxxx
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Subject: Re:  Collect word count with xslt2.0 on saxon 8
Message-ID: <44697976.1000108@xxxxxxxxxxxxx>

Hello Karen,

You can get the count of words more easily than that. First you can get
the text in a variable that belongs to an element with topic/topic but
not to other elements inside it with the same mark and then just count
the words in that.
For getting the text once we match on a topic/topic element we use a new
mode for apply-template on which we do nothing on elements with
topic/topic thus we exclude their text content.

The following stylesheet shows that

<xsl:stylesheet version="2.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:output indent="yes"/>
   <xsl:template match="/">
     <counts>
       <xsl:apply-templates/>
     </counts>
   </xsl:template>
   <xsl:template match="text()"/>
   <xsl:template match="*[contains(@class, 'topic/topic')]">
     <xsl:variable name="text">
       <xsl:apply-templates mode="getText" select="node()"/>
     </xsl:variable>
     <record>
       <text>
         <xsl:value-of select="$text"/>
       </text>
       <count>
         <xsl:value-of
 
select="count(tokenize(lower-case($text),'(\s|[,.!:;]|[n][b][s][p][;])+')[str
ing(.)])"
         />
       </count>
     </record>
     <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="*[contains(@class, 'topic/topic')]"
     mode="getText"/>
</xsl:stylesheet>

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-2011 All Rights Reserved.