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. Advertisements

  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. Advertisements

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.
Similar Threads
  1. croeltgen
    Replies:
    1
    Views:
    643
    Andrew Thompson
    Oct 25, 2004
  2. Stylus Studio
    Replies:
    0
    Views:
    677
    Stylus Studio
    Oct 5, 2004
  3. Jeff Kish
    Replies:
    1
    Views:
    477
    Tjerk Wolterink
    Oct 30, 2004
  4. Altova Announcements
    Replies:
    1
    Views:
    561
  5. Replies:
    3
    Views:
    958
    Andy Dingley
    Dec 22, 2004
  6. Nelson Minar

    XPath and XQuery in Python?

    Nelson Minar, Jan 12, 2005, in forum: Python
    Replies:
    3
    Views:
    15,278
    Uche Ogbuji
    Jan 15, 2005
  7. Bloody Viking

    XPath 2.0 expression from XQuery?

    Bloody Viking, Apr 27, 2007, in forum: XML
    Replies:
    3
    Views:
    857
    Priscilla Walmsley
    Apr 30, 2007
  8. S Perryman
    Replies:
    3
    Views:
    1,580
    Martin Honnen
    Feb 11, 2009
Loading...