• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

XSLT/XPath predicates: not(), =, !=

 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm encountering a strange situation where an XPath predicate
of the form
[a != b]
is not producing the same result as the predicate
[not(a=b)]
Here's my input XML file:

I want to print out the type of any piece of furniture whose color is different from
all those encountered already. I tried this:

and got this output, which is not what I expected:

It's missing "table", even though it's the only white piece of furniture.
It includes both "desk" and "bed", even though both are brown.
When I changed the stylesheet to this:

I got this more reasonable looking result:

I don't understand this, since the two predicates look identical in meaning.
[ October 24, 2002: Message edited by: Ron Newman ]
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron,
Please have a look at the output of the following template -

Fun stuff
Dan
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see the output (first color is null, the remainder are white) but I don't understand it.
How can [a!=b] mean something different from
[not(a=b)] ?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the output becuase preceding-sibling::furniture/color returns a node set, in which white is the color of the _first_ node in the set.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But how does my use of = vs. != change that?
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When running the following -

We get only bed, since along the preceding-sibling axis, desk has the same color as bed (brown).
None of the rest has an item along this axis with the same color.

will return the complement set - table,desk,dresser and filing cabinet. BUT not bed.

Returns desk,dresser,bed and filing cabinet. But not the first item - table.
Here, it seems, we compare against white, as we saw above.
I'm not clear about the difference.
Does the = sign in the top one mean belong to the set? If so, why doesn't != bring the complement set.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ron,
I think things will be clearer if we concentrate on the closest preceding sibling versus all of them.
I changed a bit the input to be -

The xsl -

or -

The only difference here is over table, which is some sort of an exception.
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is a good article:
Things to Know and Avoid When Querying XML Documents with XPath
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic