I have the following XSLT node:
<xsl:for-each select="Book[title != 'Moby Dick']">
....
</xsl:for-each>
However, I'd like use multiple filters in the for-each. I've tried the following, but it doesn't seem to work:
<!-- Attempt #1 -->
<xsl:for-each select="Book[title != 'Moby Dick'] or Book[author != 'Rowling'] ">
....
</xsl:for-each>
<!-- Attempt #2 -->
<xsl:for-each select="Book[title != 'Moby Dick' or author != 'Rowling']">
....
</xsl:for-each>
However, I'd like use multiple filters in the for-each
Your real question is an XPath one: Is it possible, and how, to specify more than one condition inside a predicate?
Answer:
Yes, use the standard XPath boolean operators or
and and
and the standard XPath function not()
.
In this particular case, the XPath in the select
attribute may be:
Book[title != 'Moby Dick' or author != 'Rowling']
I personally would always prefer to write an equivalent expression:
Book[not(title = 'Moby Dick') or not(author = 'Rowling')]
because the !=
operator has a non-intuitive behavior when one of its operands is a node-set.
But I am guessing that what you probably wanted was to and
the two comparissons -- not to or
them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With