How can I execute an option in the list?

In pseudocode

If Domain inList(GB,US,ES,FR Then
   Print This Html
Else
  Print This HTML
EndIf

      

+1


source to share


4 answers


This is a general form, but if you don't know the list at design time, while you can get a link to the node of nodes that represents the list, you can run a simple test like:

<xsl:when test="$listset/item[@property=$variable]">

      



where the property is $ variable = / foo / bar / @ and $ listset = / foo / list for XML

<?xml version="1.0"?>
<foo>
  <bar property="gb" />
  <list>
    <item property="gb"/>
    <item property="us"/>
  </list>
</foo>

      

+4


source


Try using xsl: select. (Also see the spec here ) It provides basic if / else functionality. EDIT - I tested 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>

      

+1


source


If you are using XSLT 2.0 given 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>


0


source


Another solution not mentioned by the current 3 answers is to have an options string against which you are comparing the value domain

. Then the following XPath expression (in an attribute @test

like <xsl:if>

or <xsl:when>

evaluates to true()

exactly when the value domain

is one of the delimited values ​​in the string (we use a space for the delimiter in this particular example):

  contains(' GB US ES ', concat(' ', domain, ' '))

Here we assume domain

there are no spaces in the value . If this cannot be guaranteed, the XPath expression can also check for this requirement:

  not(contains(domain, ' '))


and


contains(' GB US ES ', concat(' ', domain, ' '))

0


source







All Articles