|
[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 valueMichael Kay mike at saxonica.comMon Dec 4 14:24:03 PST 2006
> 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! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






