This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: appendig to multiple output files


On Thu, 24 Jan 2002 11:05:32 +0100, "Michael Wiedmann"
<michael.wiedmann@detewe.de> 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@melvaig.co.uk

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]