...">

Is there an "contains" XSL directive?

I have the following XSL snippet:

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

The if statement does not work because I could not process the syntax for contains. How to correctly express that xsl: if?

+47
xslt
Feb 20 '09 at 15:15
source share
6 answers

Of course have! For example:

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

Syntax: contains(stringToSearchWithin, stringToSearchFor)

+97
Feb 20 '09 at 15:22
source share
β€” -

there really is an xpath function that should look something like this:

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

+5
Feb 20 '09 at 15:23
source share

Use the standard XPath function contains () .

Function : boolean contains (string, string)

The contains function returns true if the first line of the argument contains the second line of the argument and otherwise returns false

+5
Feb 20 '09 at 17:30
source share

From Link to Zvon.org XSLT :

 XPath function: boolean contains (string, string) 

Hope this helps.

+2
Feb 20 '09 at 15:24
source share

It should be something like ...

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

(not verified)

See w3schools (always a good link)

+1
Feb 20 '09 at 15:20
source share
 <xsl:if test="not contains(hhref,'1234')"> 
+1
Feb 20 '09 at 15:24
source share



All Articles