XQuery version of xpath different than xslt's?

Discussion in 'XML' started by inquirydog, Jul 20, 2004.

  1. inquirydog

    inquirydog Guest

    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
     
    inquirydog, Jul 20, 2004
    #1
    1. Advertising

  2. 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 |
    -----------------------
     
    Philippe Poulard, Jul 20, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page