In Pseudo code
If Domain inList(GB,US,ES,FR Then
Print This Html
Else
Print This HTML
EndIf
Thanks
In Pseudo code
If Domain inList(GB,US,ES,FR Then
Print This Html
Else
Print This HTML
EndIf
Thanks
Try using the xsl:choose. (Also see the spec here) It provides a basic if/else functionality. EDIT- I did test and it works:
<xsl:choose>
<xsl:when test="domain = 'GB' or domain = 'US' or domain = 'ES' or domain = 'FR'">
print this html
</xsl:when>
<xsl:otherwise>
print other html
</xsl:otherwise>
</xsl:choose>
This is a*very* general form, but where you don't know the list at design-time, so long as you can get a reference to a nodeset which represents the list you can do a simple test like:
<xsl:when test="$listset/item[@property=$variable]">
where say $variable = /foo/bar/@property and $listset = /foo/list for XML
<?xml version="1.0"?>
<foo>
<bar property="gb" />
<list>
<item property="gb"/>
<item property="us"/>
</list>
</foo>
If you are using XSLT 2.0 given the file
You can use something like this:
<xsl:template match="list/item">
Property [<xsl:value-of select="@property"/>] html
</xsl:template>
<xsl:template match="list/item[some $x in ('us', 'gb') satisfies $x eq @property ]">
Property [<xsl:value-of select="@property"/>] HTML
</xsl:template>
Another solution, not mentioned by the current 3 answers is to have a string of the options against which you are comparing the value of domain
. Then the following XPath expression (in the @test
attribute of either <xsl:if>
or <xsl:when>
evaluates to true()
exactly when the value of domain
is one of the delimited values in the string (we use a space for delimiter in this concrete example):
contains(' GB US ES ', concat(' ', domain, ' '))
Here we suppose that there are no spaces in the value of domain
. If this cannot be guaranteed, the XPath expression can also verify this requirement:
not(contains(domain, ' '))
and
contains(' GB US ES ', concat(' ', domain, ' '))