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

RE: XPath 2.0

Subject: RE: XPath 2.0
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Wed, 9 Jan 2002 09:39:00 -0000
xpath exists
> I just want to check my understanding (so far) of the WDs. My
> reading is that
> (a) if nodes with ids a1 and a2 exist in the tree being queried,
>      xf:id('a1') precedes xf:id('a2')
> would raise an error because xf:id() returns a sequence, but
> the operands of
> precedes must be single nodes or empty sequences -- explicitly *not*
> non-empty sequences. The proper way to write this would therefore be
>      xf:id('a1')[1] precedes xf:id('a2')[1]

No. A "single node" and a "sequence of length one whose only item is a node"
are exactly the same thing in the data model. In this model, everything is a
> (b) if nodes with ids a1 and a2 exist in the tree being queried,
>      xf:id('a1')[1] precedes xf:id('a2')[1]
> is equivalent to
>      xf:exists( xf:id('a1') intersects xf:id('a2')/preceding::* )

In most situations yes. However, if one of the IDs doesn't exist, then I
think (without actually checking the spec) the first expression returns ()
while the second returns false. In a boolean context, () and false will be
handled the same way, but (for example) count() in the first case will give
you 0 and in the second case 1.
> And similarly
>      xf:id('a1')[1] << xf:id('a2')[1]
> is equivalent to
>      xf:exists( xf:id('a1') intersects

> xf:id('a2')/preceding::* | xf:id('a2')/ancestor::* ) )

Yes, with the same caveats, but they are equivalent only because the form of
this example guarantees that the nodes you are comparing are elements and
that they are in the same document. (If the rh operand were an attribute, it
would not be on the preceding axis or the ancestor axis of anything).

> (I thought that something in the discussion of xf:boolean(),
> which would be
> the wrong casting function to use here, suggested that I
> wouldn't need to
> use xf:exists(), because a non-empty sequence would
> automatically be treated
> as the boolean value true. But I couldn't find that when I
> went to look for
> it, and decided that using xf:exists() would make the intent
> clearer in any case.)
Yes, I think using xf:exists() to make the intention clear is good practice.
XQuery, with its stronger typing rules, will require it in some contexts,
and we may start to see XSLT implementations that allow an option of strong
type-checking as well.

A trivial point: the operator is "intersect", not "intersects".

Mike Kay

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

Current Thread


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.
First Name
Last Name
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.