[XSL-LIST Mailing List Archive Home]
[Reply To This Message]
Re: word list and count from the text in an xml docume
Subject: Re: word list and count from the text in an xml document|
From: "Mark" <mark@xxxxxxxxxxxx>
Date: Sat, 12 Jun 2010 15:37:53 -0700
Thanks Michael, I do have the book but for some stupid reason never looked!
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Sent: Saturday, June 12, 2010 3:27 PM
Subject: Re: word list and count from the text in an xml document
You will find the solution to this example on p19 of my book, XSLT 2.0 and
XPath 2.0 Programmer's Reference. In case you don't have the book, here is
the code (but if you do have the book, you get an explanation as well!)
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:output method="xml" indent="yes"/>
<xsl:for-each-group group-by="." select="
for $w in //text()/tokenize(., '\W+')[.!=''] return
<xsl:sort select="count(current-group())" order="descending"/>
This is sorted by frequency - I leave it as an exercise to sort by the
word value instead.
On 12/06/2010 21:51, Mark wrote:
I have been floundering around in the xsl-list archives for a while
looking for a way to get a listing and count of all the words in every
instance of a specific element. Thousands of hits, but I think I am not
using the correct search terms. I know what I want must be in the
archive, but I just can't seem to narrow my search enough to find it.
Given a fragment like (and concentrating on the moment on the lang="en"
<Data lang="cz"> bmla skvrnka na spodnm casti pmsmene L ve SLOV</Data>
<Data lang="en">white splotch on the lower bar on the L in SLOV</Data>
<Data lang="cz">barevn} bod pod dolnmm ramem vlevo od VHB</Data>
<Data lang="en">dot on the lower frame to the left of VHB</Data>
I would like to create a list like the one below (it would be nice to be
able to use a "stop word" list also so as to not count stuff like "on",
PURCHASE STYLUS STUDIO ONLINE TODAY!
Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!
Download The World's Best XML IDE!
Accelerate XML development with our award-winning XML IDE - Download a free trial today!
Subscribe in XML format