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.

Each kind of input source is described in an xsl:merge-source child element of the xsl:merge instruction; and the instances of that kind of input source are selected in a xsl:merge-input child of the xsl:merge-source element. 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 select="collection('log-collection')"> <xsl:merge-input 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')"> <xsl:merge-input select="transactions/transaction"/> <xsl:merge-key select="xs:dateTime(@date, @time)" order="ascending"/> </xsl:merge-source> <xsl:merge-source select="doc('log2.xml')"> <xsl:merge-input 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 function current-merge-inputs() is not yet implemented.