2008-12-16 52 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, ' '))