2009-02-20 73 views
49

我有XSL的下面的代碼片段:是否有XSL「包含」指令?

<xsl:for-each select="item"> 
    <xsl:variable name="hhref" select="link" /> 
    <xsl:variable name="pdate" select="pubDate" /> 
    <xsl:if test="hhref not contains '1234'"> 
     <li> 
     <a href="{$hhref}" title="{$pdate}"> 
      <xsl:value-of select="title"/> 
     </a> 
     </li> 
    </xsl:if> 
    </xsl:for-each> 

if語句不工作,因爲我一直沒能制定出語法包含。我將如何正確表達xsl:if?

回答

98

當然有!例如:

<xsl:if test="not(contains($hhref, '1234'))"> 
    <li> 
    <a href="{$hhref}" title="{$pdate}"> 
     <xsl:value-of select="title"/> 
    </a> 
    </li> 
</xsl:if> 

的語法是:contains(stringToSearchWithin, stringToSearchFor)

1

它應該是這樣的......

<xsl:if test="contains($hhref, '1234')"> 

(未測試)

w3schools(總是一個很好的參考BTW)

+0

在行......的? – 2009-02-20 15:22:44

+0

更正了代碼格式。 – Tomalak 2009-02-20 15:27:20

6

確實是有一個XPath包含的功能就應該是這個樣子:

<xsl:for-each select="item"> 
<xsl:variable name="hhref" select="link" /> 
<xsl:variable name="pdate" select="pubDate" /> 
<xsl:if test="not(contains(hhref,'1234'))"> 
    <li> 
    <a href="{$hhref}" title="{$pdate}"> 
     <xsl:value-of select="title"/> 
    </a> 
    </li> 
</xsl:if> 

1
<xsl:if test="not contains(hhref,'1234')"> 
6

使用標準XPath函數contains()

功能布爾包含(字符串,字符串)

如果第一個字符串參數包含第二個參數字符串contains函數返回真,否則返回假