Re: [xsl] How to use document() of doc() function with copy idiom, or how to acc

Subject: Re: [xsl] How to use document() of doc() function with copy idiom, or how to acc
From: Abel Braaksma Online <abel.online@xxxxxxxxx>
Date: Tue, 25 Jul 2006 21:37:44 +0200
Hi David,

Thanks for looking into this. I understand that the expression is expensive, though I didn't realize it before you drew attention to it. The reason I want to do this, is because I am using XSLT as export wrapper. The application gives all kinds of information about the object to be exported, even user defined ones. These are not mapped inside the loaded document and should be added using some kind of convention.

Because getting this information and using it requires quite some understanding of our product, I was creating a utility xslt that transforms all this information (zero, one, or more input files, one or more output files, target types, copies, pass-through information for the next step: xsl-fo, filters, and user defined info) in on type of object, containing a set of documents. In my example, there was only one document loaded, but in fact, there can be many, and they all appear in a structure like this (which goes into the xslt utility stylesheet to be used as an imported stylesheet as a variable called $webitor-input):

<!-- getting the following data from command line arguments and the input format, so that the wheel need not be reinvented each time -->
<input>
<doc input-filename="xxx.xml" output-hint="yyy.csv" last-change="yymmdd" created="yymmdd">
<nr-of-copies>3</nr-of-copies>
<output-format>xsl-fo</output-format>
<input-hint>addresses</input-hint>
<...>
<content>....</content>
</doc>
<doc>
....
</doc>
</input>


All because there's total freedom of a set of documents that go in and are of a certain type (or not, we have a general type), and the set of documents that go out. This way we can combine addresses with titles with localized country names, with selected text blocks and paragraphs and markup code, all from our frontend data application. The output can be pdf (with one more step for xsl-fo of course), html, csv, tab, xml, streamserve tbl format, doc1 internal format, wordml, oo doc xml format, oo calc xml format etc.

If there is a less resource eating way of tackling this, I would gladly hear about it, but I am not sure your suggestion holds here. Yet, it will run only on user command, and with not too many resources (1000 records would be much, but can happen).

Cheers,
Abel Braaksma
Nuntia B.V.



David Carlisle wrote:

I replaced it with <xsl:copy-of select="doc(xxx)" /> and now it works.



It works, but it's very expensive on memory. You end up with two copies of your input document in memory, the first one, loaded with doc() and a second new document stored in $documents that has a different structure and _copies_ of all the nodes of the first.

It's not clear why you need to wrap your source document in a new <doc>
element before applying templates, if instead you wrnt

<xsl:variable name="document" select="document($input-file)"/>

then $document would be the (original) document node.
You would then just generate the <doc> element on output,


<xsl:template name="main" match="/">
<output>
<doc>
<input-filename><xsl:value-of select="." /></input-filename>
<xsl:apply-templates select="$document/*" mode="copy" />
</doc>
</output>
</xsl:template>
David

Current Thread