web-dev-qa-db-fra.com

Existe-t-il une directive XSL "contient"?

J'ai l'extrait de code XSL suivant:

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

L'instruction if ne fonctionne pas car je n'ai pas pu déterminer la syntaxe de contains. Comment pourrais-je exprimer correctement ce xsl: si?

54
Guy

Bien sûr qu'il y en a! Par exemple:

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

La syntaxe est la suivante: contains(stringToSearchWithin, stringToSearchFor)

105
Cerebrus

il y a en effet un xpath contient une fonction qui devrait ressembler à ceci:

<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>
6
John Hunter

Utilisez la fonction standard XPathcontient () .

Fonction : booléen contient ( chaîne, chaîne)

La fonction contient renvoie true si la première chaîne d'arguments contient la deuxième chaîne d'arguments, et renvoie sinon false

6
Dimitre Novatchev

De Référence XSLT Zvon.org :

XPath function: boolean contains (string, string) 

J'espère que cela t'aides.

2
Leandro López

Cela devrait être quelque chose comme ...

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

(pas testé)

Voir w3schools (toujours une bonne référence BTW)

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