Stumped: XSLT Contains() Method Woes

admin

Administrator
Staff member
I'm trying to use the contains() method on this page, but I'm running into a strange problem. I've used this method on a similar page with success, so I'm not sure why I'm having this problem. Anyway, here's the code:
XML:
<?xml version="1.0" encoding="UTF-8"?>
<formsdocs>

<form id="1">
<title>Form 1</title>
<link>http://www.mysite.com/form1.aspx</link>
<display>true</display>
</form>

<form id="2">
<title>Form 2</title>
<link>http://www.mysite.com/form2.aspx</link>
<display>true</display>
</form>

<form id="3">
<title>Form 3</title>
<link>http://www.mysite.com/form3.aspx</link>
<display>true</display>
</form>

</formsdocs>

XSLT:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:variable name="keyword" select="''" /><!-- Pulls value from form field -->
<xsl:template match="/">
<!-- TEST -->
Keyword(s) entered: <xsl:value-of select="$keyword" /><!-- Value = <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/">http://www.webdeveloper.com/forum/archive/index.php/</a><!-- m -->"form" (without quotes) -->
<br />
<xsl:for-each select="formsdocs/formsdocs/form[contains(title, $keyword) and display ='true']">
<xsl:value-of select="" />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

HTML RESULT:

Keyword entered: form
Result: No records show up.

Keyword entered: or
Result: Shows all records that contain "or", which is all 3 of them.

As you can see, no results show up even though the node "title" does contain "form". If I enter "or" instead, those records do show up. They don't show up if the word entered is at the beginning or the end of the "title" node value.

I've also tried using the normalize-space() method to trim any whitespace, even though there is none, but that had no affect. If anyone knows what could be the cause of this issue, I'd love to get some advice. I'm hoping that it's something simple;) Thanks.
 
Back
Top