Jump to content

Stumped: Contains() Method Woes


kwilliams

Recommended Posts

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 = "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: formResult: No records show up.Keyword entered: orResult: 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.

Link to comment
Share on other sites

Well, after a suggestion from Joe Fawcett and a bit of research, I was able to come up with a solution using the translate() method. This is how I did it:<?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:variable name="lc">abcdefghijklmnopqrstuvwxyz</xsl:variable><xsl:variable name="uc">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable> <xsl:template match="/"> <!-- TEST --> Keyword(s) entered: <xsl:value-of select="$keyword" /><!-- Value = "form" (without quotes) --> <br /> <xsl:for-each select="formsdocs/formsdocs/form[contains(translate(title, $uc, $lc), $keyword) and display = 'true']"> <xsl:value-of select="" /> </xsl:for-each> </xsl:template></xsl:stylesheet>And it works great now. I'll make sure to use that method with any forms I have that use the contains() method. You can see the original thread at http://p2p.wrox.com/topic.asp?TOPIC_ID=38945. Thanks anyway:)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...