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

General rule for designing XPath expressions to return

Subject: General rule for designing XPath expressions to return items in document order?
From: "Costello, Roger L." <costello@xxxxxxxxx>
Date: Wed, 8 Jan 2014 10:33:44 +0000
 General rule for designing XPath expressions to return
Hi Folks,

This XPath expression says: select all <section> element's <head> element:

	//section/head

But that may not result in returning nodes in document order, as is the case
for this input:

<section>
	<section>
		<head/>	<!-- A -->
	</section>
	<head/>	    	<!-- B -->
</section>

"A" occurs first in the document, but is returned second. "B" occurs second in
the document, but is returned first.

To ensure that the <head> elements are selected in document order we can
rewrite the XPath expression to select all <head> elements that have a parent
<section> element:

	/descendant::head[parent::section]

Now the first <head> element in the document is the first item returned. The
second <head> element in the document is the second item returned.

I am seeking a general rule for designing XPath expressions to return the
selected items in document order. Can you provide a general rule?

/Roger

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.