This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: returning single result from apply-templates



> 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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]