Subject: [xsl] It's going to work, even if it kills me From: "Tim" <xsl@xxxxxxxxxxxxxx> Date: 27 Jun 2001 18:29:20 -0000 |
Hi Chaps, 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. An example XML file is: <articles> <article ID="article1"> <date> Tue Jun 19 10:38:02 BST 2001 </date> <detail> Tim has bought a Land Rover, for better or for worse. There will be no more tellings-off from the Better Half about wet dogs in good car. </detail> <title> Tim Buys a Land Rover </title> </article> <article ID="article2"> <date> Tue Jun 19 10:44:28 BST 2001 </date> <detail> Nice car but nothing compaired to Tim's new Landy. </detail> <title> Kirsten Buys a Vauxhall </title> </article> </articles> The XSL snip I'm playing with is: ..snip... <xsl:template match="/"> <xsl:apply-templates select="articles"> <xsl:with-param name="keywords"> <xsl:value-of select="$keywords"/> </xsl:with-param> </xsl:apply-templates> </xsl:template> <xsl:template match="articles"> <xsl:param name="keywords"/> <xsl:variable name="keywordfrag"> <xsl:call-template name="keylist"> <xsl:with-param name="keywords"> <xsl:value-of select="$keywords"/> </xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:for-each select="article[contains(translate (detail, $vLower, $vUpper),translate(xalan:evaluate($keywordfrag)//*, $vLower, $vUpper))]"> ......do stuff...... </xsl:for-each> </xsl:template> <xsl:template name="keylist"> <xsl:param name="keywords"/> <xsl:variable name="key" select="substring-before($keywords,' ')"/> <xsl:choose> <xsl:when test="string-length($key) > 0"> <keyword><xsl:value-of select="$key"/></keyword> <xsl:call-template name="keylist"> <xsl:with-param name="keywords"><xsl:value-of select="substring-after($keywords,' ')"/> </xsl:with-param> </xsl:call-template> </xsl:when> <xsl:otherwise> <keyword><xsl:value-of select="$keywords"/></keyword> </xsl:otherwise> </xsl:choose> </xsl:template> .....snip...... The result of this is that it finds all articles because the call to the keylist template does not return an xml fragment, just a list of keywords without the spaces. Idea's would be wonderful. Thanks, Tim. "In theory xsl can do anything, but what exactly is your problem?" - David Carlisle, from the XSL-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] How to define a xsl:sort', Michael Kay | Thread | RE: [xsl] It's going to work, even , Robert C. Lyons |
RE: [xsl] How to define a xsl:sort', Michael Kay | Date | [xsl] Re: How to define a xsl:sort', Dimitre Novatchev |
Month |