Xslt XSL未传递参数
问题 当从通配符模板匹配中通过时,我的参数显示为空 我的xml源代码:Xslt XSL未传递参数,xslt,xslt-1.0,Xslt,Xslt 1.0,问题 当从通配符模板匹配中通过时,我的参数显示为空 我的xml源代码: <c:control name="table" flags="all-txt-align-top all-txt-unbold"> <div xmlns="http://www.w3.org/1999/xhtml"> <thead> <tr> <th></th> &l
<c:control name="table" flags="all-txt-align-top all-txt-unbold">
<div xmlns="http://www.w3.org/1999/xhtml">
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td> </td>
</tr>
</tbody>
</c:control>
然后它调用另一个文件中的命名模板,这不应该改变我的起始引用-我应该仍然能够引用c:control[@name='table'],就好像我在匹配的模板中一样
<xsl:template name="table">
<xsl:variable name="all-txt-top">
<xsl:if test="contains(@flags,'all-txt-align-top')">true</xsl:if>
</xsl:variable>
<xsl:variable name="all-txt-unbold" select="contains(@flags,'all-txt-unbold')" />
<div xmlns="http://www.w3.org/1999/xhtml">
<table>
<xsl:apply-templates select="xhtml:*" mode="table">
<xsl:with-param name="all-txt-top" select="$all-txt-top" />
<xsl:with-param name="all-txt-unbold" select="$all-txt-unbold" />
</xsl:apply-templates>
</table>
</div>
</xsl:template>
即使我尝试将一个简单的字符串作为参数传递,它也不会传递到xhtml:thead模板
<xsl:template name="table">
<xsl:variable name="all-txt-top">
<xsl:if test="contains(@flags,'all-txt-align-top')">true</xsl:if>
</xsl:variable>
<xsl:variable name="all-txt-unbold" select="contains(@flags,'all-txt-unbold')" />
<div xmlns="http://www.w3.org/1999/xhtml">
<table>
<xsl:apply-templates select="xhtml:*" mode="table">
<xsl:with-param name="all-txt-top" select="$all-txt-top" />
<xsl:with-param name="all-txt-unbold" select="$all-txt-unbold" />
</xsl:apply-templates>
</table>
</div>
</xsl:template>
不知道我哪里出了问题。。。如果有任何帮助,我们将不胜感激。在您向我们展示的示例代码中,在匹配c:control元素后,您可以调用命名的表模板
<xsl:template match="c:control[@name='table']">
<xsl:call-template name="table" />
</xsl:template>
这意味着在表模板中,当前上下文元素是c:control。但是,在示例XML中,c:control的唯一子元素是div元素。因此,当您应用模板时
<xsl:apply-templates select="xhtml:*" mode="table">
。。。此时,它将查找与xhtml:div匹配的模板。如果没有这样的模板,则默认模板匹配将生效,这将忽略元素并处理其子元素。但这不会传递任何参数,因此匹配xhtml:thead的模板将不会有任何参数值
一种解决方案是使用一个模板专门匹配xhtml:div元素,并传递属性
<xsl:template match="xhtml:div" mode="table">
<xsl:param name="all-txt-top"/>
<xsl:param name="all-txt-unbold"/>
<xsl:apply-templates select="xhtml:*" mode="table">
<xsl:with-param name="all-txt-top" select="$all-txt-top"/>
<xsl:with-param name="all-txt-unbold" select="$all-txt-unbold"/>
</xsl:apply-templates>
</xsl:template>
事实上,如果您想处理更多元素,可以将此处的模板匹配更改为“xhtml:*”,使其更通用。ahhh。我以为参数会一直延续到下一个可用的匹配。谢谢你,我的好朋友。非常感谢。
<xsl:template match="xhtml:div" mode="table">
<xsl:param name="all-txt-top"/>
<xsl:param name="all-txt-unbold"/>
<xsl:apply-templates select="xhtml:*" mode="table">
<xsl:with-param name="all-txt-top" select="$all-txt-top"/>
<xsl:with-param name="all-txt-unbold" select="$all-txt-unbold"/>
</xsl:apply-templates>
</xsl:template>