xsl-list
[Top] [All Lists]

Re: preceding...please help understanding...

2002-09-07 10:58:44
Bill Carter wrote:
I am having trouble understanding preceding.

It seems to be more of a problem with understanding the != operator:

  <xsl:for-each select="stocks/ticker">
  <xsl:if test=". != preceding::ticker">

preceding::ticker returns a node set with all ticker element nodes
which precede the current node. The "." on the left side is a node
set with the current node. The != operator now compares the string
value of each node from the node seft to left of it with the string
value of each node of the right node set, and, this is the important
point retruns true if any of these comparisions returns true.
For the "AAA" ticker, the right node set is empty, therefore no
comparision takes place, and the whole expresssion returns false,
and the "AAA" is not output.
for the each of "CBS" ticker, the expression returns true, because
 "CBS" != "BIG", and both nodes are output.

Why doesn't the previous one work as expected. What am I missing here about preceding?

You should use "not(. = preceding::ticker)". It's not a problem with
preceding, it's the fact that != works somewhat unintuitively for
node sets: $a=$b and $a!=$b can return both true for the same values
of $a and $b, and not($a=$b) is not the same as $a!=$b.

J.Pietschmann


XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>