【问题标题】:Adding "mode" attibute to xslt stylesheet将“节点”属性添加到 xslt 样式表
【发布时间】:2012-08-05 11:22:02
【问题描述】:

我有一个可以正常运行的 xslt 样式表。我需要将 mode 属性添加到所有 xsl:template 元素。为了将属性添加到所有元素并仍然使样式表正常运行,我应该记住哪些事实。任何帮助表示赞赏。提前谢谢你。

【问题讨论】:

    标签: xslt xslt-2.0


    【解决方案1】:

    这当然取决于样式表和您要使用的确切模式值,有关详细信息,请参阅http://www.w3.org/TR/xslt20/#modes

    假设您有类似没有模式属性的模板,例如

    <xsl:template match="foo">
      <bar>
        <xsl:apply-templates/>
      </bar>
    </xsl:template>
    

    如果您想使用某种模式,则必须同时更改 xsl:templatexsl: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:template 的地方都添加了“模式”。现在样式表不能正常工作。我在所有地方都应用了相同的模式名称。我错过了什么吗?
    • “我在所有有 xsl:template 和 xsl:template 的地方都添加了“模式”是一个错误吗?我试图指出您需要更改xsl:template 以及xsl:apply-templates。如果您在尝试添加模式后有一个具体的样式表失败,那么最好(至少对我来说)向我们展示输入、原始样式表、新样式表、您想要的输出和一个你明白了。
    • 我错过了一个模板。非常感谢您的回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-03
    • 2011-09-04
    • 2013-02-13
    • 1970-01-01
    • 2012-09-25
    相关资源
    最近更新 更多