[PLEASE READ] XPath query help

Discussion in 'XML' started by gfrommer@hotmail.com, Jan 6, 2005.

  1. Guest

    Hello everyone,

    I've been reading through a bunch of XPath tutorials and am
    confused by a couple items. First, is it possible to have multiple
    predicates in my XPath statement. For example, the following xpath
    statement: "//AAA/BBB[@name="b1"]/c[c=6]" should only return the last
    <c> node containing the 6, correct? Also consider the statement
    "//AAA/BBB[@name="b1" or @name="b2"]" returns the first two <BBB>
    items, correct? the and's and or's in the predicates are all right yes?

    Does JAXEN support these kind of queries?

    <AAA>
    <BBB name = "b1">
    <c>4</c>
    </BBB>
    <BBB name = "b2">
    <c>5</c>
    </BBB>
    <BBB name = "b1">
    <c>6</c>
    </BBB>
    </AAA>


    Also, I read that the "|" operator will combine the results of several
    xpath queries. I understand that it will append the results into one
    big list... Is there any way to preform logical AND's OR's and NOT's on
    the results of each query and have it combine into one big list?
    (Instead of a simple append)

    Thanks everyone
    , Jan 6, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Hi,

    > I've been reading through a bunch of XPath tutorials and am
    > confused by a couple items. First, is it possible to have multiple
    > predicates in my XPath statement.

    AFAIK, perfectly possible
    > For example, the following xpath
    > statement: "//AAA/BBB[@name="b1"]/c[c=6]" should only return the last
    > <c> node containing the 6, correct?


    Almost. write that as <xsl:value-of select="//AAA/BBB[@name='b1']/c[.=6]"/>
    Mark the two types of quotes and the '.' in stead of 'c'

    > Also consider the statement
    > "//AAA/BBB[@name="b1" or @name="b2"]" returns the first two <BBB>
    > items, correct? the and's and or's in the predicates are all right yes?

    Yes, (but mind the quotes)

    > Does JAXEN support these kind of queries?


    I have no idea.

    > <AAA>
    > <BBB name = "b1">
    > <c>4</c>
    > </BBB>
    > <BBB name = "b2">
    > <c>5</c>
    > </BBB>
    > <BBB name = "b1">

    Is suppose that should be 'b3'
    > <c>6</c>
    > </BBB>
    > </AAA>
    >
    >
    > Also, I read that the "|" operator will combine the results of several
    > xpath queries. I understand that it will append the results into one
    > big list... Is there any way to preform logical AND's OR's and NOT's on
    > the results of each query and have it combine into one big list?
    > (Instead of a simple append)

    Only if you use XPath2.0 or extension functions.

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-view.cgi?userid=38041)
    Veni, vidi, wiki (http://www.wikipedia.org)
    Joris Gillis, Jan 6, 2005
    #2
    1. Advertising

  3. Also, I read that the "|" operator will combine the results of several
    xpath queries. I understand that it will append the results into one
    big list... Is there any way to preform logical AND's OR's and NOT's on
    the results of each query and have it combine into one big list?
    (Instead of a simple append)


    No, XPath 1 doesn't have lists, only sets (which are unordered) and | is
    set-union not append, so if $a is a variable holding a node then $a | $a
    is just one copy of the node in $a, not two. so | is not at all like a
    list append.

    David
    David Carlisle, Jan 6, 2005
    #3
  4. Guest

    Re: XPath query help

    David Carlisle wrote:
    > Also, I read that the "|" operator will combine the results of

    several
    > xpath queries. I understand that it will append the results into

    one
    > big list... Is there any way to preform logical AND's OR's and

    NOT's on
    > the results of each query and have it combine into one big list?
    > (Instead of a simple append)
    >
    >
    > No, XPath 1 doesn't have lists, only sets (which are unordered) and |

    is
    > set-union not append, so if $a is a variable holding a node then $a |

    $a
    > is just one copy of the node in $a, not two. so | is not at all like

    a
    > list append.
    >
    > David


    The set-union that you are talking about... is that the equivilent of a
    logical AND between those two sets?

    Thanks
    , Jan 6, 2005
    #4
  5. Re: XPath query help

    writes:

    > David Carlisle wrote:
    >
    > The set-union that you are talking about... is that the equivilent of a
    > logical AND between those two sets?
    >
    > Thanks


    Not sure what you mean. There are some basic operations that apply to
    sets, union and intersection being the main ones. Logical operations
    don't naturally apply to sets. There are of course various ways to map
    logical operations into set ones, union can be read as and or or
    depending on the circumstances.

    <xsl:template match="foo|bar">

    that template matches any element that is foo OR bar
    or you could say
    that template matches foo elements AND bar elements

    David
    David Carlisle, Jan 7, 2005
    #5
    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.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,956
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,368
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    507
  4. David Gordon

    xpath query query

    David Gordon, May 18, 2005, in forum: XML
    Replies:
    2
    Views:
    780
    David Gordon
    May 18, 2005
  5. KK
    Replies:
    2
    Views:
    524
    Big Brian
    Oct 14, 2003
Loading...

Share This Page