[Home] [By Thread] [By Date] [Recent Entries]
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-ofselect="count(tokenize(lower-case($text),'(\s|[,.!:;]|[n][b][s][p][;])+')[string(.)])"
/>
</count>
</record>
<xsl:apply-templates/>
</xsl:template> <xsl:template match="*[contains(@class, 'topic/topic')]"
mode="getText"/>
</xsl:stylesheet>on your sample input it gives: <?xml version="1.0" encoding="UTF-8"?>
<counts>
<record>
<text>
communications and information theory
top element
elements can be nested Generalized Markup
Language defined by ISO 8879.
</text>
<count>17</count>
</record>
<record>
<text>
communications and information theory
top element
elements can be nested (for a number of
technical reasons beyond the scope of this article).
</text>
<count>22</count>
</record>
<record>
<text>
communications and information theory
top element
elements can be nested maintain repositories
of structured documentation for more than a decade, but it is
not well
</text>
<count>25</count>
</record>
<record>
<text> But
the metrics for XML on the Web communications and
information theory
top element
elements can be nested measures, or are a
little polluted by voodoo ideology about good </text>
<count>29</count>
</record>
</counts>Best Regards, George --------------------------------------------------------------------- George Cristian Bina <oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com Karen McAdams wrote: I have the following structure that i need to collect
|

Cart



