[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: output the result of the transformation twice, in

Subject: Re: output the result of the transformation twice, indented and not indented, without duplicating the code
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 May 2022 19:01:21 -0000
Re:  output the result of the transformation twice
On Mon, May 23, 2022 at 06:39:30PM -0000, Wolfhart Totschnig wolfhart.totschnig@xxxxxxxxxxx scripsit:
> I have an XSL stylesheet that produces a large XML document. I would like to
> output the XML document twice, once indented (for human readability) and
> once not indented (for faster access by other scripts). I am wondering
> whether this can be done from within a single stylesheet.

Sure; you store the result document in a variable, minimally:

<xsl:template name="xsl:initial-template">
  <xsl:variable name="result">
    <xsl:apply-templates select="/node()"/>
  </xsl:variable>

  <xsl:result-document href="$path-for-humans" format="main" indent="true">
    <xsl:sequence select="$result"/>
  </xsl:result-document>
  <xsl:result-document href="$path-for-machines" format="main" indent="false">
    <xsl:sequence select="$result"/>
  </xsl:result-document>

</xsl:template>

<xsl:output name="main" /> has all the other things like doctype or
encoding or method you would want to define for the result documents, so
you can change them in one place.

This works in XSLT 2 or XSLT 3; it won't work in 1.

The second result document can just be xsl:sequence and will emit the
variable as the transform's result document, but that way you can't use
the single named output to control everything but the indent for both
result documents.

-- 
Graydon Saunders  | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor  ("That passed, so may this.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.