[xquery-talk] getting an attrib value from another attrib value

Robert Walpole robert.walpole at devon.gov.uk
Mon Dec 4 14:54:01 PST 2006


That explains the error I was getting then. Returning the string value
of the uid attribute would appear to be the answer for me in this case.

Thanks to you both for your help.
Rob Walpole


> -----Original Message-----
> From: Michael Kay [mailto:mike at saxonica.com] 
> Sent: 04 December 2006 14:24
> To: 'John Snelson'; Robert Walpole
> Cc: talk at x-query.com
> Subject: RE: [xquery-talk] 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/
> 
> 
> 



More information about the talk mailing list