Skip to content
xsl:result-document

xsl:result-document

Writes its body to a secondary output document instead of the primary result tree.

<xsl:result-document href="chapter-{@id}.html">
  ...
</xsl:result-document>

The primary result of a transformation is always produced; xsl:result-document adds additional output documents alongside it. In the goxslt API the secondary documents are returned as the SecondaryDocuments map on TransformResult; the CLI writes them to disk relative to the primary output’s directory.

href is an attribute value template, so a single instance of the instruction inside a loop can produce many output documents.

Attributes

Attribute Description
href Output URI as an AVT. Required.
format Name of an xsl:output declaration to use for serialization.
method, indent, encoding, … Same attributes as xsl:output, applied to this document only.

Example

Splitting one input into multiple output files, one per chapter:

<xsl:for-each select="//chapter">
  <xsl:result-document href="chapter-{@id}.xml">
    <chapter id="{@id}">
      <xsl:copy-of select="*"/>
    </chapter>
  </xsl:result-document>
</xsl:for-each>