Is there an XSL “contains” directive?

后端 未结 6 687
一向
一向 2020-12-28 11:49

I have the following snippet of XSL:

  
    
    

        
相关标签:
6条回答
  • 2020-12-28 11:59

    It should be something like...

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

    (not tested)

    See w3schools (always a good reference BTW)

    0 讨论(0)
  • 2020-12-28 12:02

    Use the standard XPath function contains().

    Function: boolean contains(string, string)

    The contains function returns true if the first argument string contains the second argument string, and otherwise returns false

    0 讨论(0)
  • 2020-12-28 12:05

    From Zvon.org XSLT Reference:

    XPath function: boolean contains (string, string) 
    

    Hope this helps.

    0 讨论(0)
  • 2020-12-28 12:09
    <xsl:if test="not contains(hhref,'1234')">
    
    0 讨论(0)
  • 2020-12-28 12:18

    Sure there is! For instance:

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

    The syntax is: contains(stringToSearchWithin, stringToSearchFor)

    0 讨论(0)
  • 2020-12-28 12:19

    there is indeed an xpath contains function it should look something like:

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

    0 讨论(0)
提交回复
热议问题