【问题标题】:XSL: match two template with same XPath-expression but different code inside other templateXSL:匹配两个具有相同 XPath 表达式但在另一个模板中的代码不同的模板
【发布时间】:2014-06-20 07:35:28
【问题描述】:

我知道,当我指定该子模板的 XPath 表达式时,我可以在另一个模板中调用 xsl:apply-templates。

在我的 xsl 文件中,我得到了一个

<xsl:template match="/">
    <xsl:apply-templates select="root/values" />
</xsl:template>

<xsl:template match="root/values>
    <xsl:value-of select="value/key" />
</xsl:template>

现在我想在另一个上下文中再次对根/值的子节点做一些事情 - 我如何在我的主模板中匹配这个模板?

<xsl:template match="root/values>
    <xsl:for-each select="value">
        <xsl:value-of select="key" />
    </xsl:for-each>
</xsl:template>

【问题讨论】:

  • 如果您展示了您正在使用的 XML 示例以及您希望获得的输出,这可能会有所帮助。谢谢!

标签: templates xslt xpath xslt-2.0


【解决方案1】:

我想你想使用一种模式:

<xsl:template match="/">
    <xsl:apply-templates select="root/values" />
    <xsl:apply-templates select="root/values" mode="m1" />
</xsl:template>

<xsl:template match="root/values>
    <xsl:value-of select="value/key" />
</xsl:template>

<xsl:template match="root/values" mode="m1">
    <xsl:for-each select="value">
        <xsl:value-of select="key" />
    </xsl:for-each>
</xsl:template>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-11-02
    • 1970-01-01
    • 2021-10-27
    • 2011-10-12
    • 2011-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多