Alex Dawn
Alex Dawn

Reputation: 55

How do you test if a value is matches one of a set of values?

so in python you can test like

if value in ('value1', 'value2', ...):
    ....

is there an equilvant in xslt?

<xsl:if test="@value in ('value1', 'value2')">
    ...
</xsl:if>

without having to use a long list of or statements @value = 'value1' or @value = 'value2'

Upvotes: 1

Views: 864

Answers (1)

zx485
zx485

Reputation: 29022

You can use sets like this which check if a value is part of a set:

<xsl:if test="@value = ('value1', 'value2')">
  Succeeds if @value is either "value1" or "value2"
</xsl:if>

An inferior alternative in XSLT-1.0 is using a separate check for every value like this:

<xsl:if test="@value = 'value1' or @value = 'value2'">
  Succeeds if @value is either "value1" or "value2"
</xsl:if>

Upvotes: 2

Related Questions