我有模板
<xsl:template match="node" mode="some_mode">
<xsl:value-of select="child1" />
<xsl:value-of select="child2" />
<xsl:value-of select="child3" />
</xsl:template>
我想应用模板,这样在一种情况下它将选择模板中指定的所有节点
<xsl:apply-templates select="node" mode="some_node" /> <!-- select all inside the node tag -->
在另一种情况下,我想限制输出,例如不要选择
<xsl:apply-templates select="node" mode="some_node" /> <!-- select only some tags from the node tag -->
换句话说,我将多次使用此模板,并且在应用时希望控制输出。我可以定义变量,但是文档说,一旦定义了变量,就无法更改它的值。该参数可能会扭曲,但我对此并不满意。
最佳答案
恐怕不修改模板就无法实现。
您可以考虑将模板输出存储在变量中,然后对其进行处理以除去child1
和child2
值。但是我想您将无法猜测输出的哪一部分来自child1
和/或child2
。
或者,您可以开发另一个执行该替代操作的模板。
编辑:另一个想法:
也许可以在应用模板之前应用过滤来去除child1
和child2
(这将是多遍XSL转换)。
关于xslt - 根据条件应用整个模板或模板部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9311287/