pevik
pevik

Reputation: 4801

xsl:message terminate attribute defined by variable (setup like)

Define xsl variable to for terminate attribute of <xsl:message> does not work:

<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>

This forces me to use terminate="no" for all cases:

<xsl:message terminate="no">
    <xsl:text>foo</xsl:text>
</xsl:message>
<!-- ... -->
<xsl:message terminate="no">
    <xsl:text>bar</xsl:text>
</xsl:message>

and then replace all of them if I change my mind instead of changing just single variable.

I prefer solution for XSLT 1.0 (using xsltproc).

Upvotes: 2

Views: 539

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167571

In 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 doesn't seem to allow it.

So the main XSLT like approach in that case of XSLT 1 would be to write one stylesheet to create a second stylesheet, for that you have to use xsl:namespace-alias, as shown in https://www.w3.org/TR/xslt-10/#section-Creating-Elements-and-Attributes.

Upvotes: 2

Related Questions