[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
[xsl] variable and html code
Subject: [xsl] variable and html code From: François Parlant <fxp.xsl@xxxxxxxxxxx> Date: Fri, 27 Jun 2003 12:39:34 +0200 |
Sorry to ask again so soon for help about this code. In my recursion, only the last step is correctly output with the html. I've replaced all the *value-of * by *copy-of*, as mentioned in the FAQ for variable call ("mot" means 'word', it's a one word string, so no need to change it : I've tried anyway it complexified all but didn't do better) And I can't put my eyes on the bug. <!-- Gets text nodes and send them to "gloss" template for treatment --> <xsl:template match="text()"> <xsl:variable name="replaced_text"> <xsl:call-template name="gloss"> <xsl:with-param name="input_text"> <xsl:copy-of select="."/> </xsl:with-param> </xsl:call-template> </xsl:variable> <xsl:copy-of select="$replaced_text" /> </xsl:template> <xsl:template name="gloss"> <!-- takes the first word in dictionnary and sends the text nodes to "links" for treatment--> <xsl:param name="input_text"/> <xsl:param name="pos">1</xsl:param> <xsl:param name="word" select="(document('mongloss.xml')//mot)[1]"/> <xsl:variable name="addlinks"> <xsl:call-template name="links"> <xsl:with-param name="input_text"> <xsl:copy-of select="$input_text"/> </xsl:with-param> <xsl:with-param name="word" select="(document('mongloss.xml')//mot)[$pos]" /> <xsl:with-param name="pos" select="$pos" /> </xsl:call-template> </xsl:variable> <!--Calls the same template with next word of the dictionnary if there is one--> <xsl:choose> <xsl:when test="$pos < count(document('mongloss.xml')//mot)"> <xsl:call-template name="gloss"> <xsl:with-param name="input_text"> <xsl:copy-of select="$addlinks"/> </xsl:with-param> <xsl:with-param name="pos" select="$pos + 1" /> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:copy-of select="$addlinks"/> </xsl:otherwise> </xsl:choose> </xsl:template> <!-- Parses the text node checking for the dictionnary word. Adds a <a> element around the word in the string. Starts with the first part of string, and recalls the template with the rest of the string--> <xsl:template name="links"> <xsl:param name="input_text"/> <xsl:param name="word"/> <xsl:param name="pos">1</xsl:param> <xsl:choose> <xsl:when test="contains($input_text, $word)"> <xsl:copy-of select="substring-before($input_text, $word)"/> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="(document('mongloss.xml')//mot)[$pos]/following-sibling::classe"/> </xsl:attribute> <xsl:value-of select="$word"/> </xsl:element> <xsl:call-template name="links"> <xsl:with-param name="input_text" > <xsl:copy-of select="substring-after($input_text, $word)"/> </xsl:with-param> <xsl:with-param name="word" select="$word"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:copy-of select="$input_text"/> </xsl:otherwise> </xsl:choose> </xsl:template> If someone can spot the mistake or tell me what other trap of variable I fell in, thanks a lot. François If only the Jeni Tennison exemple in "string replacement" used html code... ;-) XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XSLT Recursive Templates, Dr. Robert Spiske | Thread | Re: [xsl] variable and html code, David Carlisle |
Re: [xsl] XSLT Recursive Templates, David Carlisle | Date | Re: [xsl] variable and html code, David Carlisle |
Month |