[PLEASE READ] XPath query help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gfrommer@hotmail.com

    [PLEASE READ] XPath query help

    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

  • Joris Gillis

    #2
    Re: [PLEASE READ] XPath query help

    Hi,
    [color=blue]
    > 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.[/color]
    AFAIK, perfectly possible[color=blue]
    > For example, the following xpath
    > statement: "//AAA/BBB[@name="b1"]/c[c=6]" should only return the last
    > <c> node containing the 6, correct?[/color]

    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'
    [color=blue]
    > 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?[/color]
    Yes, (but mind the quotes)
    [color=blue]
    > Does JAXEN support these kind of queries?[/color]

    I have no idea.
    [color=blue]
    > <AAA>
    > <BBB name = "b1">
    > <c>4</c>
    > </BBB>
    > <BBB name = "b2">
    > <c>5</c>
    > </BBB>
    > <BBB name = "b1">[/color]
    Is suppose that should be 'b3'[color=blue]
    > <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)[/color]
    Only if you use XPath2.0 or extension functions.

    regards,
    --
    Joris Gillis (http://www.ticalc.org/cgi-bin/acct-v...i?userid=38041)
    Veni, vidi, wiki (http://www.wikipedia.org)

    Comment

    • David Carlisle

      #3
      Re: [PLEASE READ] XPath query help

      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

      Comment

      • gfrommer@hotmail.com

        #4
        Re: XPath query help


        David Carlisle wrote:[color=blue]
        > Also, I read that the "|" operator will combine the results of[/color]
        several[color=blue]
        > xpath queries. I understand that it will append the results into[/color]
        one[color=blue]
        > big list... Is there any way to preform logical AND's OR's and[/color]
        NOT's on[color=blue]
        > 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 |[/color]
        is[color=blue]
        > set-union not append, so if $a is a variable holding a node then $a |[/color]
        $a[color=blue]
        > is just one copy of the node in $a, not two. so | is not at all like[/color]
        a[color=blue]
        > list append.
        >
        > David[/color]

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

        Thanks

        Comment

        • David Carlisle

          #5
          Re: XPath query help

          gfrommer@hotmai l.com writes:
          [color=blue]
          > David Carlisle wrote:
          >
          > The set-union that you are talking about... is that the equivilent of a
          > logical AND between those two sets?
          >
          > Thanks[/color]

          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

          Comment

          Working...