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
 
$doc/servicetree/@id/string()
 
or
 
string($doc/servicetree/@id)
 
(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
http://www.saxonica.com/
 
PS: general XQuery coding questions that aren't specifically relevant to the Saxon product are better asked on talk@xquery.com; 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: saxon-help-admin@lists.sourceforge.net [mailto:saxon-help-admin@lists.sourceforge.net] On Behalf Of Pierre Martins
Sent: 27 February 2006 11:37
To: saxon-help@lists.sourceforge.net
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 $doc/servicetree/@id
 
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 $doc/servicetree/@id/text() 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