xsl:on-non-empty

Used to allow conditional content construction to be made streamable. Outputs the enclosed content only if the containing sequence also generates "ordinary" content.

The instruction can appear anywhere in a sequence constructor (and more than once). The content is output in the appropriate place among "ordinary" output.

Although intended primarily to make streaming applications easier to write, the instruction can also be handy irrespective of streaming to avoid evaluating complex conditions more than once.

Category: instruction
Content: sequence-constructor
Permitted parent elements: any XSLT element whose content model is sequence-constructor; any literal result element

Attributes

select?

expression

The value to be output when the containing sequence constructor delivers a non-empty result. This may be computed using either a select attribute or using child instructions of the xsl:on-non-empty element.

Saxon availability

Available in XSLT 3.0. From Saxon 9.8, available in all editions. Implemented in Saxon-PE and Saxon-EE since Saxon 9.7. Available for all platforms.

Notes on the Saxon implementation

New in XSLT 3.0, and implemented since Saxon 9.7.

Examples

The following code generates a header and footer only if there is content, however it is not guaranteed-streamable because it processes child item-for-sale elements more than once:

<xsl:if test="exists(item-for-sale)"> <h1>Items for Sale</h1> </xsl:if> <xsl:apply-templates select="item-for-sale"/> <xsl:if test="exists(item-for-sale)"> <p>Total value: {accumulator-after('total-value')}</p> </xsl:if>

To make this streamable, it can be rewritten using the xsl:on-non-empty instruction:

<xsl:sequence> <xsl:on-non-empty> <h1>Items for Sale</h1> </xsl:on-non-empty> <xsl:apply-templates select="item-for-sale"/> <xsl:on-non-empty> <p>Total value: {accumulator-after('total-value')}</p> </xsl:on-non-empty> </xsl:sequence>

Links to W3C specifications

XSLT 3.0 Specification

See also

xsl:on-empty

xsl:where-populated