Subject: RE: [xsl] It's going to work, even if it kills me From: "Robert C. Lyons" <boblyons@xxxxxxxxxx> Date: Wed, 27 Jun 2001 15:57:30 -0400 |
Tim wrote: > I'm still trying to pass a list of keywords in as a parameter and then > search an xml file for any of those words and return a html formatted > header list. Tim, I hope that you're still alive and well. :-) I could not find the problem in your stylesheet fragment. Perhaps the following stylesheet, which does not use any extensions, would help you. The output is text rather than HTML. I tested it using SAXON and your sample XML doc. <?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="text"/> <xsl:strip-space elements="*"/> <xsl:param name="keywords"/> <xsl:variable name="a_z" select="'abcdefghijklmnopqrstuvwxyz'"/> <xsl:variable name="A_Z" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/> <xsl:variable name="keywords_lower_case" select="translate( $keywords, $A_Z, $a_z )" /> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="detail"> <xsl:variable name="found_keyword"> <xsl:call-template name="find_keyword"> <xsl:with-param name="string" select="translate( ., $A_Z, $a_z )"/> <xsl:with-param name="keywords" select="$keywords_lower_case"/> </xsl:call-template> </xsl:variable> <xsl:if test="$found_keyword = 'yes' "> <xsl:text>Found a keyword in '</xsl:text> <xsl:value-of select="."/> <xsl:text>'
</xsl:text> </xsl:if> </xsl:template> <xsl:template name="find_keyword"> <xsl:param name="string"/> <xsl:param name="keywords"/> <!-- Returns 'yes' if $string contains a keyword. Returns 'no' if $string does not contain any keywords. --> <xsl:variable name="keyword"> <xsl:choose> <xsl:when test="contains( $keywords, ' ' )"> <xsl:value-of select="substring-before($keywords,' ')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$keywords"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:choose> <xsl:when test="$keyword != '' "> <xsl:choose> <xsl:when test="contains( $string, $keyword )"> <xsl:value-of select="'yes'"/> </xsl:when> <xsl:otherwise> <xsl:variable name="remaining_keywords" select="substring-after( $keywords, ' ' )"/> <xsl:call-template name="find_keyword"> <xsl:with-param name="string" select="$string"/> <xsl:with-param name="keywords" select="$remaining_keywords"/> </xsl:call-template> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:value-of select="'no'"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template match="text()"/> </xsl:stylesheet> Best regards, Bob <sig name = 'Bob Lyons' title = 'XML Consultant' company = 'Unidex, Inc.' phone = '+1-732-975-9877' email = 'boblyons@xxxxxxxxxx' url = 'http://www.unidex.com/' product = 'XML Convert: transforms flat files to XML and vice versa' /> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] It's going to work, even if i, Tim | Thread | Re: [xsl] It's going to work, even , David Carlisle |
[xsl] Re: How to define a xsl:sort', Dimitre Novatchev | Date | [xsl] Re: Default attribute value t, Dimitre Novatchev |
Month |