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

Re: text() function

Subject: Re: text() function
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 25 Apr 2005 15:04:58 -0400
text function
An afterthought: if you wanted to avoid concatenating all of the text nodes because you might have a very large amount of text, you can check all individual text nodes using:

//text()[contains(.,'blah')

This will also not give you a false positive in the following:

<p>bl<b>ah</b></p>

So, you will have to decide if the above contains "blah" or not. If you decide that it does not contain "blah", then you would be obliged to check all individual text nodes as described above, instead of any concatenation like that described in my earlier post copied below.

I hope this helps.

. . . . . . Ken

p.s. btw, text() is *not* a function, it is a grammatical construct in XPath for NodeTest ... it does not "call" anything as a function would call code

At 2005-04-25 14:57 -0400, I wrote:
At 2005-04-25 11:46 -0700, Sameer N wrote:
I am trying to look if the word blah exists in the entire document.

contains( /, "blah" )



Is there any difference between
//*[conatins(text(), "blah")]
and
//*[conatins( . , "blah")]

Absolutely. Each one has a predicate that addresses a single node, the first one addresses the value of the first text child node of the current node, while the second one addresses the value of current node.


Is the using of string() function as suggested in the blog right way to do what I want... because I read in one book that string() only matches the first element found and does not go thru the entire document trying to match all elements found.

XPath states that the value of an element is the concatenation of all descendent text nodes, hence the difference in what you have above: checking that "." contains "blah" checks the concatenation of all text nodes of the current node.


In my suggestion above you would search the value of the root node, which is the value of the document element, which is the value of the concatenation of all text nodes in the entire document.

I hope this helps.

. . . . . Ken


--
World-wide on-site corporate, govt. & user group XML/XSL training.
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Breast Cancer Awareness  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

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