Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 19th, 2005, 04:18 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please Help Xslt comparison problem

Hi
I am very new to xslt and have been trying to figure this out for a long time but without much sucess.
What I am trying to do is to allow a user type a word into an input box and then that it would search an rss file to see if that word is contain in the desciption of an item.

I have the following code, which works for me if I was searching for the language:
<xsl:copy-of select="item[contains(description/@language,$filterBy)]"/>
so in the rss file desciption is as follows:
<description language="en">some text</description>

What I would like to have is the description to be like:
<description>some text</description>
and then in my xslt file be able to compare "some text" with my parameter which at the moment is "language". I do not know how to access the text and how to compare it to the parameter.

Please if any one can help me it would be much appreciated,
Kind Regards


 
Old February 19th, 2005, 04:24 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

To test if the content equals $param use

item[description = $param]

To test if it contains the value of $param as a substring, use

item[contains(description, $param)]



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 19th, 2005, 04:40 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help. I cant get it working though are you saying that I should have it like
<xsl:template match="channel">
<xsl:copy-of select="item[description = @language]"/>
</xsl:template>
if my rss file looks like this:
<channel>
.......
<item>
   ........
     <description>contain text</description>
</item>

and @language contains what the user entered, so that it will only copy it if entered "contain text".

also tried saying
<xsl:variable name="selectLang" select="@language"/>
and then doing
<xsl:copy-of select="item[description = $selectLang]"/>

Everything just returns an empty file?!!

Kind Regards



 
Old February 19th, 2005, 07:08 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

@language refers to an attribute in your source XML document. If you want the variable to refer to something "that the user entered", you will need to supply "what the user entered" as a parameter to the transformation, and reference it within the stylesheet as say $selectedLang where there is a top-level stylesheet parameter <xsl:param name="selectedLang"/>. The details of how to supply parameters to the transformation depend on the XSLT processor that you are using.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old February 21st, 2005, 01:37 PM
Registered User
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for all your help. I get it now. Thank you,

Kind Regards






Similar Threads
Thread Thread Starter Forum Replies Last Post
apostrophe ' problem in comparison ramniwas Visual Basic 2005 Basics 4 April 3rd, 2008 11:21 PM
xsl:when test - comparison problem pelicanPaul XSLT 1 June 29th, 2007 04:45 AM
Date comparison problem mat41 Javascript 3 August 30th, 2006 09:22 PM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
Access Form problem, date comparison jackson_jl VB Databases Basics 0 March 9th, 2005 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.