xslt实现递归

xml文件如下

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='三级子表.xsl'?>
<xmldata ver='1.0'>
  <property>
    <segdaysale1st title='类别列表'>
      <segdaysale2nd title='中类类别列表'>
        <segdaysale3rd title='小类类别列表'></segdaysale3rd>
      </segdaysale2nd>
    </segdaysale1st>  
  </property>

</xmldata>

xslt文件如下

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
        <html>
            <body>
                <ul>
                    <xsl:call-template name="foreachProperty">
                        <xsl:with-param name="nodes" select="xmldata/property/child::*"/>
                    </xsl:call-template>
                </ul>
            </body>
        </html>   
    </xsl:template>

    <!-- 遍历所有的property -->
    <xsl:template name="foreachProperty">
        <xsl:param name="nodes"/>
        <xsl:for-each select="$nodes">
            <li>
                <xsl:value-of select="attribute::title"/>                
            </li>                                                                      
            <xsl:if test="child::*">
            <ul>
                <xsl:call-template name="foreachProperty">
                    <xsl:with-param name="nodes" select="child::*"/>
                </xsl:call-template>
            </ul>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>     
</xsl:stylesheet>


 

posted @ 2010-08-13 14:45  kuailewangzi1212  阅读(396)  评论(0编辑  收藏  举报