xsl:merge

The xsl:merge instruction is new in XSLT 3.0, and is first implemented in Saxon-EE 9.4. The purpose of the instruction is to allow streamed merging of two or more pre-sorted input files, but the current implementation in Saxon is unstreamed.

The syntax of xsl:merge has been significantly changed in the February 2013 draft of XSLT 3.0, and the revised syntax is implemented in Saxon 9.5. The implementation is still unstreamed.

In the new syntax, each kind of input source is described in an xsl:merge-source child element of the xsl:merge instruction; if there are multiple instances of that kind of input source, they are selected in the for-each attribute of the xsl:merge-source element, while the select attribute selects the actual nodes forming the input sequence. The processing to be carried out on each group of input items sharing a value for the merge key is defined in a xsl:merge-action element.

The following example merges a homogenous collection of log files, each already sorted by timestamp:

<xsl:merge> <xsl:merge-source for-each="collection('log-collection')" select="events/event"/> <xsl:merge-key select="@timestamp" order="ascending"/> </xsl:merge-source> <xsl:merge-action> <xsl:sequence select="current-group()"/> </xsl:merge-action> </xsl:merge>

The following example merges two log files with different internal structure:

<xsl:merge> <xsl:merge-source select="doc('log1.xml')" select="transactions/transaction"/> <xsl:merge-key select="xs:dateTime(@date, @time)" order="ascending"/> </xsl:merge-source> <xsl:merge-source select="doc('log2.xml')" select="eventdata/transfer"/> <xsl:merge-key select="@timestamp" order="ascending"/> </xsl:merge-source> <xsl:merge-action> <xsl:apply-templates select="current-group()"/> </xsl:merge-action> </xsl:merge>

The bind-group, bind-key, and bind-source variables are not yet implemented. Instead, the current-group() and current-grouping-key() functions are used, as in earlier releases.

The function current-merge-inputs() is not implemented.

Saxon 9.5 implements the sort-before-merge attribute, which allows the input to be sorted before merging.