I have a xml like:
<movies> <movie name="aaa"> ... </movie> <movie name="bbb"> ... </movie> <movie name="ccc"> ... </movie> <movie name="ddd"> ... </movie> <movie name="eee"> ... </movie> </movies>
I would like to get the name of the movie if it is not 'aaa', or 'bbb', or 'ddd'. So I would like my output to be:
Because I have several restrictions, I don't think it's suitable to use 'xsl:if'..I wrote my xslt like (I'm using xslt 1.0):
<xsl:value-of select="movies/movie/@name[not(self::aaa) and not(self::bbb) and not(self:ddd)]"/>
But the compiler complained there is a syntax error in this sentence..and I can't figure out why..
So could anybody help me with this? Many thanks!!
Try this XPath expression:
movies/movie[@name!='aaa' and @name!='bbb' and @name!='ddd']/@name
or this one:
movies/movie/@name[.!='aaa' and .!='bbb' and .!='ddd']
the latter is shorter, but the former can be easily extended to check for other return not only the name, but the whole
<movie> element - just remove
/@name at the end. Or if you want that for the second, just add
/.. at the end.
Consider using an expression like this, in case there are too-many values for comparison:
/*/movie[not(contains('|aaa|bbb|ddd|', concat('|', @name, '|)))]/@name
This selects any
name attribute of any
movie element that is a child of the top element of the XSLT document, and whose value (of the
name attribute) isn't one of the strings in the pipe-separated list of string values
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