Re: [xsl] appendig to multiple output files

Subject: Re: [xsl] appendig to multiple output files
From: Trevor Nash <tcn@xxxxxxxxxxxxx>
Date: Thu, 24 Jan 2002 13:23:09 +0000
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