[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

getting an attrib value from another attrib value

Michael Kay mike at saxonica.com
Mon Dec 4 14:24:03 PST 2006


  getting an attrib value from another attrib value
> The answer you are looking for is:
> 
> doc("...")//*[@name = "Torquay"]/@uid
> 

Just one little addition:

> I have only got so far as being able to get the whole node (i.e. 
> including children) with the matching name attribute as follows:

The query above returns a single attribute node (assuming Torquay is unique,
which I know it is!).

If you changed the expression to:

doc("...")//*[@name = "Torquay"]

then the query still returns only a single node, this time an element node.

The difference only arises if and when you serialize the results. The
serialization spec actually doesn't allow you to serialize a single
attribute node (because the result of serialization is always XML, and in
lexical XML attributes can't exist in isolation). That means the serializer
will choke on John Snelson's solition. When you serialize an element, on the
other hand, you get the whole subtree rooted at that element. But if you are
returning the results to an application, without serialization, then either
expression is fine.

If you just want the uid as a string you can write:

doc("...")//*[@name = "Torquay"]/@uid/string()

Michael Kay
http://www.saxonica.com/




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