xsl:message 变量定义的终止属性(类似设置)
xsl:message terminate attribute defined by variable (setup like)
为 <xsl:message>
的 terminate
属性定义 xsl 变量不起作用:
<xsl:variable name="TERMINATE_ON_ERROR" select="'no'" />
<xsl:message terminate="$TERMINATE_ON_ERROR">
<xsl:text>foo</xsl:text>
</xsl:message>
<!-- ... -->
<xsl:message terminate="$TERMINATE_ON_ERROR">
<xsl:text>bar</xsl:text>
</xsl:message>
这迫使我在所有情况下都使用 terminate="no"
:
<xsl:message terminate="no">
<xsl:text>foo</xsl:text>
</xsl:message>
<!-- ... -->
<xsl:message terminate="no">
<xsl:text>bar</xsl:text>
</xsl:message>
如果我改变主意而不是只改变单个变量,然后替换所有变量。
我更喜欢 XSLT 1.0 的解决方案(使用 xsltproc
)。
在 XSLT 2 中(https://www.w3.org/TR/xslt20/#message) and 3 (https://www.w3.org/TR/xslt-30/#element-message) the terminate
attribute allows an attribute value template (e.g. terminate="{$TERMINATE_ON_ERROR}"
) but XSLT 1 https://www.w3.org/TR/xslt-10/#message 似乎不允许。
因此,在 XSLT 1 的情况下,主要的类似 XSLT 的方法是编写一个样式表来创建第二个样式表,为此您必须使用 xsl:namespace-alias
,如 https://www.w3.org/TR/xslt-10/#section-Creating-Elements-and-Attributes 所示。
为 <xsl:message>
的 terminate
属性定义 xsl 变量不起作用:
<xsl:variable name="TERMINATE_ON_ERROR" select="'no'" />
<xsl:message terminate="$TERMINATE_ON_ERROR">
<xsl:text>foo</xsl:text>
</xsl:message>
<!-- ... -->
<xsl:message terminate="$TERMINATE_ON_ERROR">
<xsl:text>bar</xsl:text>
</xsl:message>
这迫使我在所有情况下都使用 terminate="no"
:
<xsl:message terminate="no">
<xsl:text>foo</xsl:text>
</xsl:message>
<!-- ... -->
<xsl:message terminate="no">
<xsl:text>bar</xsl:text>
</xsl:message>
如果我改变主意而不是只改变单个变量,然后替换所有变量。
我更喜欢 XSLT 1.0 的解决方案(使用 xsltproc
)。
在 XSLT 2 中(https://www.w3.org/TR/xslt20/#message) and 3 (https://www.w3.org/TR/xslt-30/#element-message) the terminate
attribute allows an attribute value template (e.g. terminate="{$TERMINATE_ON_ERROR}"
) but XSLT 1 https://www.w3.org/TR/xslt-10/#message 似乎不允许。
因此,在 XSLT 1 的情况下,主要的类似 XSLT 的方法是编写一个样式表来创建第二个样式表,为此您必须使用 xsl:namespace-alias
,如 https://www.w3.org/TR/xslt-10/#section-Creating-Elements-and-Attributes 所示。