xsl-list
[Top] [All Lists]

Re: RFC: Recursive Template Improvements/Suggestions ??

2005-06-02 22:02:45


Hi,
     Looks ok to me except that I don't see the need for the $stop
variable. Why not just do

   bt(&quot;<xsl:value-of select="concat($tbef, $taft)"/>&quot;);
at the point where you find $taft does not contain a quote instead of
recursing oncemore with $stop set to 1.

Cheers,
Omprakash.V











                                                                                
                                   
                    "Bovy,                                                      
                                   
                    Stephen J"           To:     
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>                              
   
                    <STEPHEN.Bovy        cc:     (bcc: omprakash.v/Polaris)     
                                   
                    @ca.com>             Subject:     RFC: [xsl] Recursive 
Template Improvements/Suggestions ??    
                                                                                
                                   
                    06/03/2005                                                  
                                   
                    05:45 AM                                                    
                                   
                    Please                                                      
                                   
                    respond to                                                  
                                   
                    xsl-list                                                    
                                   
                                                                                
                                   
                                                                                
                                   




Any suggestions for improvement would be greatly appreciated !!!

<script tag >

var btxt = "";                     // frame 3 table body text
function bt ( tg ) { btxt += tg; } // concatenate text function

// write table body frame 3
function body ( ) {
  bt('<html> ');

  ( ... )

  <  apply templates >

  ( ... )

   return btxt;
 } // end of table body frame 3

<end script tag>

<xsl:template match="/*/*/*" >
bt('<td align="center" nowrap="nowrap"> ');
<xsl:call-template name="repQuote">
  <xsl:with-param name="tbef" select="string('')"/>
  <xsl:with-param name="taft" select="."/>
  <xsl:with-param name="stop" select="0"/>
</xsl:call-template>
bt('</td> ');
</xsl:template>

Here is my XSL recursive template function:

<!-- recursive function to escape quote in -->
<!-- javaScript string literal assignment  -->
<xsl:template name="repQuote">
  <xsl:param name="tbef"/>
  <xsl:param name="taft"/>
  <xsl:param name="stop"/>
<xsl:choose>
<xsl:when test="$stop=0">
  <xsl:choose>
  <xsl:when test="contains($taft,'&quot;')">
    <xsl:variable name="xx">
      <xsl:value-of select="substring-before($taft,'&quot;')"/>
    </xsl:variable>
    <xsl:variable name="yy">
      <xsl:value-of select="substring-after($taft,'&quot;')"/>
    </xsl:variable>
    <xsl:variable name="zz">
      <xsl:value-of select="concat($xx,'\&quot;')"/>
    </xsl:variable>
    <xsl:call-template name="repQuote">
      <xsl:with-param name="tbef" select="concat($tbef,$zz)"/>
      <xsl:with-param name="taft" select="$yy"/>
      <xsl:with-param name="stop" select="0"/>
    </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:call-template name="repQuote">
      <xsl:with-param name="tbef" select="concat($tbef,$taft)"/>
       <xsl:with-param name="taft" select="string('')"/>
       <xsl:with-param name="stop" select="1"/>
     </xsl:call-template>
   </xsl:otherwise>
   </xsl:choose>
 </xsl:when>
 <xsl:otherwise>
   bt(&quot;<xsl:value-of select="$tbef"/>&quot;);
 </xsl:otherwise>
 </xsl:choose>
 </xsl:template>

Any suggestions for improvement would be greatly appreciated !!!

-----Original Message-----
From: JBryant(_at_)s-s-t(_dot_)com [mailto:JBryant(_at_)s-s-t(_dot_)com]
Sent: Thursday, June 02, 2005 2:43 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Re:[xsl] Recursive Template ??

If you dig around in the archives, you'll find oodles of them.

The general principle works like this:

<xsl:template name="someTemplate">
  <xsl:param name="someParam"/>
  <!-- do some processing -->
  <xsl:if test="not(someStopCondition)"
    <xsl:call-template name="someTemplate">
      <xsl:with-param name="someParam" select="someValue"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Endless variations exist, but they all come down to the following
proposition: recuse as many times as needed until some stop condition is
met.

HTH

Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)





"Bovy, Stephen J" <STEPHEN(_dot_)Bovy(_at_)ca(_dot_)com>
06/02/2005 04:32 PM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com


To
<xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
cc

Subject
Spam:[xsl] Recursive Template ??






Is it possible to create a "recursive" template
that works in the same way as a recursive function call ???


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






This e-Mail may contain proprietary and confidential information and is sent 
for the intended recipient(s) only. 
If by an addressing or transmission error this mail has been misdirected to 
you, you are requested to delete this mail immediately.
You are also hereby notified that any use, any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and/or publication of this e-mail message, contents or its 
attachment other than by its intended recipient/s is strictly prohibited.

Visit Us at http://www.polaris.co.in

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>