【发布时间】:2012-08-05 11:22:02
【问题描述】:
我有一个可以正常运行的 xslt 样式表。我需要将 mode 属性添加到所有 xsl:template 元素。为了将属性添加到所有元素并仍然使样式表正常运行,我应该记住哪些事实。任何帮助表示赞赏。提前谢谢你。
【问题讨论】:
我有一个可以正常运行的 xslt 样式表。我需要将 mode 属性添加到所有 xsl:template 元素。为了将属性添加到所有元素并仍然使样式表正常运行,我应该记住哪些事实。任何帮助表示赞赏。提前谢谢你。
【问题讨论】:
这当然取决于样式表和您要使用的确切模式值,有关详细信息,请参阅http://www.w3.org/TR/xslt20/#modes。
假设您有类似没有模式属性的模板,例如
<xsl:template match="foo">
<bar>
<xsl:apply-templates/>
</bar>
</xsl:template>
如果您想使用某种模式,则必须同时更改 xsl:template 和 xsl:apply-templates,例如
<xsl:template match="foo" mode="m1">
<bar>
<xsl:apply-templates mode="m1"/>
</bar>
</xsl:template>
在apply-templates 上,您有不同的选择,但是您可以使用
<xsl:template match="foo" mode="m1">
<bar>
<xsl:apply-templates mode="#current"/>
</bar>
</xsl:template>
虽然只有一个模式值,但没有区别。
【讨论】:
xsl:template 以及xsl:apply-templates。如果您在尝试添加模式后有一个具体的样式表失败,那么最好(至少对我来说)向我们展示输入、原始样式表、新样式表、您想要的输出和一个你明白了。