http://blog.csdn.net/huwei2003/article/details/48338165
问题描述:当template的match已经写好路径时,其中的select还是要写全部的路径才行,有没有好的解决办法
原因:因为template的调用方式是call-template,当使用call-template时,select中的路径都要从根节点开始选取;但是apply-template可以继承节点层次
xsl代码举例:
其中的arNav模板,for-each语句中的select路径不能够继承match中的路径,match只是匹配元素,但不作为当前节点,所以子元素不可以继续往下继承
<xsl:template name="main-article" match="article/front/article-meta"> <div class="cMain show clearfloat" id="mainArticle"> <xsl:call-template name="arNav"/> <xsl:call-template name="arText"/> </div> </xsl:template><!--1.2.2.1.3.1.1 左侧一级标题导航栏--> <xsl:template name="arNav" match="article/body/sec"> <ul id="arNav"> <xsl:for-each select="article/body/sec"> <xsl:choose> <xsl:when test="./@id='s1'"> <li class="navItem nav0 navActive"> <a href="#section0"> <xsl:value-of select="title"/> </a> </li> </xsl:when> <xsl:otherwise> <li class="navItem nav0"> <a href="#section0"> <xsl:value-of select="title"/> </a> </li> </xsl:otherwise> </xsl:choose> </xsl:for-each> </ul> </xsl:template>