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?
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.
XSLT <xsl:value-of> Element.
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!
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.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With