I'm trying to setup a condition that
tests the value of the current node in
the for-each, but I'm doing something
wrong:
The first thing that is incorrect is the syntax:
.[='1112']
There are two things wrong here:
Within [ and ] there is no predicate: the "=" operator needs two arguments but only one is provided.
.[x = y]
is still invalid syntax, although the predicate is OK. This has to be specified as:
self::node()[condition]
The second thing in the provided code that can be improved is the <xsl:for-each>
instruction, which isn't necessary at all; A single XPath expression will be sufficient.
To summarize, one possible XPath expression that evaluates to the required boolean value is:
/books/book[. = '1112']
If it is really necessary that the condition be tested inside the <xsl:for-each>
instruction, then one correct XPath expression I would use is:
. = '1112'
The above is a string comparison and may not evaluate to true()
if there are spaces around. Therefore, a numerical comparison may be better:
. = 1112