2008-12-16 48 views

回答

4

这是一个非常一般形式,但如果你不知道在设计时的名单,只要你能得到一个节点集的引用代表名单,你可以做一个简单的测试,如:

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

哪里说$变量= /富/酒吧/ @财产和$用于XML

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

尝试使用xsl:choose.(另见the spec here)它提供了一个基本的if/else功能。编辑 - 我做了测试,它的工作原理:

<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> 
0

LISTSET = /富/清单如果你使用XSLT 2.0指定的文件

您可以使用这样的事情:
<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

另一种解决方案,而不是由目前的3个回答是提到有一串您正在比较domain的值的选项。然后下面的XPath表达式(在任<xsl:if><xsl:when>@test属性的计算结果为true()准确时的domain的值是(我们在本具体例中使用空间分隔符)字符串中的分隔的值中的一个:

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

在这里,我们假设有在domain值没有空格如果不能得到保证,XPath表达式也可以验证这一点要求:

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