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

Re: appendig to multiple output files

Subject: Re: appendig to multiple output files
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Thu, 24 Jan 2002 13:23:09 +0000
Re:  appendig to multiple output files
On Thu, 24 Jan 2002 11:05:32 +0100, "Michael Wiedmann"
<michael.wiedmann@xxxxxxxxx> wrote:

>But how do I append data to the "other" document in my various templates 
>without overwriting the output file?
>
I think you have in mind templates like this:

<xsl:template match="x">
   <xsl:document href="file">
       <<templates to specify content of 'file' >>
   </xsl:document>
   <<templates to specify main document>>
</xsl:template>

with the idea that all the fragments for 'file' should be stuck
together to make one document.  But that isn't the way XSLT 1.1 was
written, instead it interprets this as writing many small documents to
the same destination - so you only get one of them, or an error.
I'm not sure, but I think the Xalan extension does work the way you
expect.

Two solutions:

1.  Use modes.
<xsl:template match="/">
   <xsl:document href="file">
      <xsl:apply-templates mode="file"/>
   </xsl:document>
   <xsl:apply-templates/>
</xsl:template>

<xsl:template match="x" mode="file">
    <<templates to specify content of 'file' >>
</xsl:template>

<xsl:template match="x">
   <<templates to specify main document>>
</xsl:template>

This implies traversing the document twice, which might be a problem
for a large document.  In theory a clever processor could do it in one
pass, but I'm not aware of any that have this optimisation - its not a
common enough case.

So method 2:

Use a SAX filter on the output.  Change the xsl:document elements to
something else say my:document, so that you produce one large document
- then the filter strips out these elements and writes them to the
other file.

Hope this helps,
Trevor Nash

--
Traditional training & distance learning,
Consultancy by email

Melvaig Software Engineering Limited
voice:     +44 (0) 1445 771 271 
email:     tcn@xxxxxxxxxxxxx

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.