[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

variable and html code

Subject: variable and html code
From: François Parlant <fxp.xsl@xxxxxxxxxxx>
Date: Fri, 27 Jun 2003 12:39:34 +0200
html variable
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 &lt; 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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.