xslt传值
<xsl:template match= "/ ">
<html>
<body>
<xsl:call-template name= "bodyTable ">
<xsl:with-param name= "ndname "> root/tjjm </xsl:with-param>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name= "bodyTable ">
<xsl:param name= "ndname "/>
<table width= "100% " bgcolor= "#dddddd ">
<xsl:for-each select= "$ndname ">
<tr>
<td>
<xsl:value-of select= "@title "/>
</td>
</tr>
<tr>
<td>
<xsl:call-template name= "itemTable "/>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
因为我的XML里的root下的一级子节点的名称都不一样,所以想通过传值传入节点名称 再遍历
下面是我的xml格式
<root>
<zzhd title= "正在活动3 ">
<item title= "哈哈笑看风去 " url= "3 " pic= " " />
<item title= "搞笑的评书选段 " url= "2 " pic= " " />
<item title= "六月的雨 " url= "2 " pic= " " />
</zzhd>
<tjzz title= "推荐作者1 ">
<item title= "搞笑的评书选段 " url= " " pic= " " />
<item title= "六月的雨 " url= " " pic= " " />
<item title= "六月的雨 " url= " " pic= " " />
<item title= "六月的雨 " url= " " pic= " " />
<item title= "t " url= "t " pic= "t " />
<item title= "1 " url= "1 " pic= "1 " />
</tjzz>
</root>
[解决办法]
下面是一个片段,我工作中写的。你参考一下。
<xsl:stylesheet version= "2.0 " xmlns:xsl= "http://www.w3.org/1999/XSL/Transform ">
<xsl:param name= "gUnitID "/>
<xsl:template match= "/ ">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match= "ExamDoc ">
<xsl:if test= "$gUnitID!= ' ' ">
<xsl:apply-templates select= "Unit[@ID=$gUnitID] "/>
</xsl:if>
<xsl:if test= "$gUnitID= ' ' ">
<xsl:apply-templates/>
</xsl:if>
</xsl:template>