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

Re: returning single result from apply-templates

Subject: Re: returning single result from apply-templates
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 10 Oct 2000 10:49:06 GMT
xpath predicate text node content
> So the ()[integer] construct guarantees a single node? 

[integer] construct always guarantees at most one node from th enode set
to which the predicate is applied.

so bar[1]  gives you the first bar node from the nodes selected by
child::bar (or th eempty node set if there are no such nodes).



Reasonable (if not DC accurate) view then would be

> (1)   foo//bar[1] applies the whole path as many times as are found in the
> src document

Not really.

> whereas
> 
> (2)	(foo//bar)[1] creates the nodeset in () first, then applies the
> predicate?

Yes.


The xpath selection only happens once in each case.

 foo//bar[1] 

is short for

child::foo/descendant-or-self::node()/child::bar[1]

the scope of the [1] here is just the last step ie child::bar

so you get the first bar child of every descendant of every foo child.

  (foo//bar)[1]

is short for
  (...)[1]

so you get the first node selected by whatever I should have filled in
for ....

You can of course mix and match

(  (foo//xxx)[1] | (foo[4]//yyy[3])[2]  )  [1]

selects the first node in document order that is either

the first xxx that is a descendant of fff
or
the second yyy that is a third yyy child of a descendant
of the fourth foo


So, the important thing to consider with [ predicates ]  is
which node set they apply to. In the abscence of () then this is
normally just the last step ie the stuff after the last /
but using () you can apply them to any node set.



David


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.