[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: word list and count from the text in an xml docume
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:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/"> <wordcount> <xsl:for-each-group group-by="." select=" for $w in //text()/tokenize(., '\W+')[.!=''] return lower-case($w)"> <xsl:sort select="count(current-group())" order="descending"/> <word word="{current-grouping-key()}" frequency="{count(current-group())}"/> </xsl:for-each-group> </wordcount> </xsl:template> </xsl:stylesheet> This is sorted by frequency - I leave it as an exercise to sort by the word value instead. Michael Kay Saxonica On 12/06/2010 21:51, Mark wrote: Hi,
|
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
|