Reputation: 746
I'm finding that while this test returns true:
test="string-length(foo) = 0"
However, for some reason, both of these tests are returning false:
test="foo = ''"
test="foo = null"
Any idea what might be going on? Is there some other state that foo could be in that would result in a 0 length, while still not being equal to '' or null?
Additionally - if I output:
X<xsl:value-of select="foo" />X
outputs: XX
Upvotes: 1
Views: 140
Reputation: 163262
If foo is an empty node-set then string(foo)
is "", and string-length(foo)
is zero, but foo = ''
is false. XPath is full of surprises.
The explanation is that foo = ""
doesn't mean string(foo) = ""
as you might expect, but rather some $F in foo satisfies $F = ""
(which you can write in full in XPath 2.0). And if foo is an empty set then the existential test is clearly false.
Upvotes: 2
Reputation: 167401
Well if you do test="foo = null"
you compare the foo
child element(s) of the context node to the null
child element(s) of the context node.
Upvotes: 1