Stream large XML product catalogues with XSLT 3.0

Filter a supplier’s XML catalogue and write the inventory import incrementally. Compare the output and peak process memory against the same transformation with materialized input.

DCoding.Xml 1.2.0Example: Professional

Packages: DCoding.Xml.Xslt.Streaming

On this page

Transform products independently

The catalogue is a flat sequence of product records. Each has a SKU, status, price and name. The transformation skips discontinued products and keeps only the fields required by the inventory import. Every decision can be made while processing that product, so the stylesheet can emit the result in source order.

Make the catalogue transformation streamable

The streamable mode passes through the catalogue and applies a template per product. The template reads that product’s attributes and consumes its name once. In .NET, the example binds the Professional streaming provider during compilation and execution and sends the result directly to a file stream.

XSLT 3.0
<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" indent="no" omit-xml-declaration="yes" encoding="UTF-8" />
  <xsl:mode streamable="yes" on-no-match="shallow-skip" />

  <xsl:template match="/">
    <inventory><xsl:apply-templates /></inventory>
  </xsl:template>

  <xsl:template match="product">
    <xsl:if test="@state = 'active'">
      <item sku="{@sku}" price="{@price}"><xsl:value-of select="name" /></item>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

Run the Professional example

Configure the authenticated d-coding NuGet feed and set DCODING_XML_LICENSE_FILE to the path of a Professional or evaluation licence that covers this release. Extract the ZIP and run the command in the project directory. The project generates its own input and prints the directory containing the input and the two outputs. Allow a few minutes for the comparison, or use 1,000 entries for a quick check.

Shell
dotnet run -c Release -- 100000

Download example project ZIP · C# · .NET 8 · Professional

Compare relative peak process memory

Both modes use the same input file and the same mapping rules. The materialized variant loads the entire source document. The streaming variant reads it incrementally, and the example checks execution diagnostics for materialization or fallback. Both write to files whose SHA-256 hashes must match on every run.

  • Each variant runs three times in fresh processes. The comparison divides the two medians of peak process memory, with materialized processing set to 100%.
  • Peak process memory includes the .NET runtime and the transformation. The input generation and output comparison run in the parent process.

Result with 100,000 products

In this comparison on Windows with .NET 8 and DCoding.Xml 1.2.0, streaming reduced peak process memory by 87.5%. Both variants produced byte-identical files with 75,000 active products. To compare your own workload, run both variants against the same input and runtime.

Execution modeRelative peak process memory
Without streaming100%
With streaming12.5%

Sign in

Choose how you would like to sign in.

Email + password Google Microsoft
Create accountForgot password?