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
(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; XPath questions can equally well be asked on xsl-list at Both lists give you a very high chance of getting an authoritative answer to your question, often more than one.

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

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 ?

Pierre Martins