[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

Count a specific word in a document

Bas de Bakker bas at x-hive.com
Thu Jun 14 09:53:40 PDT 2007


  Count a specific word in a document
Michael Kay wrote:

> In fact the use of /text() is very common in XQuery circles, and in my view
> it's usually wrong. You nearly always want the string value of the element
> rather than its text node children: /string() rather than /text(), except as
> I say that it's usually implicit.

Indeed, which allows me to return to one of my pet peeves: bad examples 
in the XQuery Use Cases document, which many people use as examples. In 
this case, we read:

1.1.9.9 Q9

In the document "books.xml", find all section or chapter titles that 
contain the word "XML", regardless of the level of nesting.

Solution in XQuery:

<results>
   {
     for $t in doc("books.xml")//(chapter | section)/title
     where contains($t/text(), "XML")
     return $t
   }
</results>

Regards,
Bas de Bakker



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