Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XQuery version of xpath different than xslt's?

Reply
Thread Tools

XQuery version of xpath different than xslt's?

 
 
inquirydog
Guest
Posts: n/a
 
      07-20-2004
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
 
Reply With Quote
 
 
 
 
Philippe Poulard
Guest
Posts: n/a
 
      07-20-2004
inquirydog wrote:
> 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
--
Cordialement,

///
(. .)
-----ooO--(_)--Ooo-----
| Philippe Poulard |
-----------------------
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Where to get stand alone Dot Net Framework version 1.1, version2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? MowGreen [MVP] ASP .Net 5 02-09-2008 01:55 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? PA Bear [MS MVP] ASP .Net 0 02-05-2008 03:28 AM
Re: Where to get stand alone Dot Net Framework version 1.1, version 2.0, version 3.0, version 3.5, version 2.0 SP1, version 3.0 SP1 ? V Green ASP .Net 0 02-05-2008 02:45 AM
xsdb better than RSS, RDF, XQuery, XPath, and XSLT most of the time ;) aaronwmail-usenet@yahoo.com XML 3 12-22-2004 10:02 PM
[ANN] Stylus Studio 6 Adds new Support for XSLT 2.0, XPath 2.0, XQuery,XML Schema, Legacy Data Integration and XML Mapping Stylus Studio XML 0 10-05-2004 06:17 PM



Advertisments