Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an XSL "contains" directive?

Tags:

xslt

I have the following snippet of 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> 

The if statement does not work because I haven't been able to work out the syntax for contains. How would I correctly express that xsl:if?

like image 974
Guy Avatar asked Feb 20 '09 15:02

Guy


People also ask

How do you check not contains in XSLT?

I would probably check for not(starts-with(substring-after(link, '://'), 'www.msdn.com')) , to make the match unambiguous. You could do add something like count(blog[not(contains(following-sibling::link, 'msdn'))]) to get the number of matching blog nodes and use an xsl:choose for the different sections.

Which xsl element is used to extract information from XML document?

XSLT <xsl:value-of> Element.

How do you declare a global variable in XSLT?

XSLT <xsl:variable>The <xsl:variable> element is used to declare a local or global variable. Note: The variable is global if it's declared as a top-level element, and local if it's declared within a template. Note: Once you have set a variable's value, you cannot change or modify that value!

Is xsl otherwise required?

The xsl:otherwise element is an optional child of the xsl:choose element. The xsl:choose element is used to make a choice when there are two or more possible courses of action. It provides a means for conducting multiple conditions testing.


1 Answers

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)

like image 176
Cerebrus Avatar answered Oct 10 '22 17:10

Cerebrus