Get attributes in an XPath expression whithin an XQuery

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get attributes in an XPath expression whithin an XQuery

Pierre Martins-2
Hi,
I have a very simple question:
I want to get the value of an attribute inside an XQuery:
 
Here is my XQuery in fact the document in the real life is itself a variable):
let $doc := document{<servicetree id='SER1735434134'/>} return [hidden email]
 
This is almost working,
The result I get is => 'id="SER1735434134"'
My problem is that I only want 'SER1735434134'.
 
Is there a proper way to do this ?
Using [hidden email]() return me the fowllowing error (which is logic in a way): The child axis starting at an attribute() node will never select anything
 
I have seen some former mails where this question was asked when the attribute value was get from an XSL but I've got no idea on how doing this in an XQuery ?
 
Thanks,
Perre

________________________
Pierre Martins
Reply | Threaded
Open this post in threaded view
|

RE: Get attributes in an XPath expression whithin an XQuery

Michael Kay
The result you are getting from your query is actually an attribute node: if what you see is 'id="SER1735434134"' then this is because the software invoking the query has chosen to display an attribute node in this particular way (or because this is the display style that you selected, explicitly or implicitly).
 
If you want your query to return the string value of the attribute node you can write it as
 
 
or
 
 
(the difference between the two is that the first expression converts a sequence of attributes into a sequence of strings; the second expression requires a single attribute node).
 
/text() means /child::text(), and in the XPath data model attribute nodes do not have children.
 
Michael Kay
 
PS: general XQuery coding questions that aren't specifically relevant to the Saxon product are better asked on [hidden email]; XPath questions can equally well be asked on xsl-list at mulberrytech.com Both lists give you a very high chance of getting an authoritative answer to your question, often more than one.


From: [hidden email] [mailto:[hidden email]] On Behalf Of Pierre Martins
Sent: 27 February 2006 11:37
To: [hidden email]
Subject: [saxon] Get attributes in an XPath expression whithin an XQuery

Hi,
I have a very simple question:
I want to get the value of an attribute inside an XQuery:
 
Here is my XQuery in fact the document in the real life is itself a variable):
let $doc := document{<servicetree id='SER1735434134'/>} return [hidden email]
 
This is almost working,
The result I get is => 'id="SER1735434134"'
My problem is that I only want 'SER1735434134'.
 
Is there a proper way to do this ?
Using [hidden email]() return me the fowllowing error (which is logic in a way): The child axis starting at an attribute() node will never select anything
 
I have seen some former mails where this question was asked when the attribute value was get from an XSL but I've got no idea on how doing this in an XQuery ?
 
Thanks,
Perre

________________________
Pierre Martins