XQuery version of xpath different than xslt's?

inquirydog

Usenet Archive
Joined
Dec 13, 2003
Messages
21
Reaction score
0
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt?

document("document.xml")//a/@b

For the following sample document:

<root>
<a b="1" />
<a b="2" />
</root>

for XQuery (using 'java kawa.repl --xquery -e
'document("document.xml")//a/@b') I get:

b=1 b=2

for xslt (using <xsl:value-of select="document('document.xml')//a/@b" />) I get:

1

There seem to be two large descrepancies- first, XQuery includes the attribute name as well as the value (b=1 instead of 1), and XQuery lists all the attributes, while xslt only lists the first. Am I just confused or is there some ambiguity with this?

thanks
-I
 

Philippe Poulard

Usenet Archive
Joined
Dec 20, 2001
Messages
412
Reaction score
0
inquirydog said:
Can anyone explain to me why the following XQuery expression (a simple xpath expression) returns a different result than the same expression in xslt?

document("document.xml")//a/@b

For the following sample document:

<root>
<a b="1" />
<a b="2" />
</root>

for XQuery (using 'java kawa.repl --xquery -e
'document("document.xml")//a/@b') I get:

b=1 b=2

for xslt (using <xsl:value-of select="document('document.xml')//a/@b" />) I get:

1

There seem to be two large descrepancies- first, XQuery includes the attribute name as well as the value (b=1 instead of 1), and XQuery lists all the attributes, while xslt only lists the first. Am I just confused or is there some ambiguity with this?

thanks
-I

hi,

i guess that with xslt you displayed the result of the xpath query with something like <xsl:value-of> don't you ?

in this case, the string function is involved to convert the result to the output tree

how does the string function works ?
as explained here : http://www.w3.org/TR/xpath#function-string a node-set is converted to a string by returning the string-value of the node in the node-set that is first in document order.

apply this to your case :
node set of attr b=1 and attr b=2
keep the first node attr b=1
extract its value 1
1 is your result

now, try to browse your result with <xsl:for-each>, and use 2 <xsl:value-of> to display the name of each node, and its value

you should obtain the same result as xquery
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top