Goodspeed

导航

Xslt中递归的实现

<?xml version="1.0" encoding="gb2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
<xsl:template match="/">
        
<!--      addFunction(addString,currentNum,theResult)     -->
        
<xsl:call-template name="addFunction">
            
<xsl:with-param name="addString" >1</xsl:with-param>
            
<xsl:with-param name="currentNum">1</xsl:with-param>
            
<xsl:with-param name="theResult" >1</xsl:with-param>
     
</xsl:call-template>
     
    
</xsl:template>

    
<!-- 
        void addFunction(string addString,int currenNum,int thgeResult) 
        {
            Console.Write(addString + "+" + currenNum.ToString() + " =");
            Console.WriteLine((currenNum+thgeResult).ToString());

            if (currentNum<10)
            {
                addFunction(addString+"+"+currentNum.ToString(),currenNum+1,thgeResult+currenNum); 
            }
        }
    
-->
    
<xsl:template name="addFunction">
        
<xsl:param name="addString"/>
        
<xsl:param name="currentNum"/>
        
<xsl:param name="theResult"/>
        
        
<xsl:value-of select="concat($addString,'+',$currentNum)"/> = 
        
<xsl:value-of select="$theResult + $currentNum"/>
        
<br/>
        
<xsl:if test="$currentNum &lt;= 10 ">
            
<xsl:call-template name="addFunction">
                
<xsl:with-param name="addString" select="concat($addString,'+',$currentNum)"/>
                
<xsl:with-param name="currentNum" select="$currentNum + 1"/>
                
<xsl:with-param name="theResult" select="$theResult + $currentNum"/>
            
</xsl:call-template>
         
</xsl:if>
    
</xsl:template>
</xsl:stylesheet>

posted on 2005-08-06 17:35  Goodspeed  阅读(1716)  评论(0编辑  收藏  举报