[PLEASE READ] XPath query help

G

gfrommer

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
 
J

Joris Gillis

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?

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,
 
D

David Carlisle

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
 
G

gfrommer

David said:
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
 
D

David Carlisle

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,836
Latest member
login dogas

Latest Threads

Top