|
Subject: Re: [xsl] Breaking up a large XML document into several smaller ones From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx> Date: Fri, 11 Jan 2008 15:13:25 +0000 |
On 11/01/2008, Glen Mazza <glen.mazza@xxxxxxxxx> wrote:
> Hello,
>
> I searched the XSLT FAQ and could not find an answer to this. If only
> for proof-of-concept (we may find better solutions not needing this),
> I am interested in breaking up a very large XML document into multiple
> smaller ones, and was wondering if XSLT would be a good solution for
> this. For example, if I have the following:
>
> <order>
> <widgets>
> <widget.../>
> <widget.../>
> ... (about 100000 widgets) ...
> </widgets>
> </order>
>
> And, as output, I would like about hundred documents of 1000 widgets
> each, with the last document having the remainder (possibly not 1000)
> widgets:
>
> <order>
> <widgets>
> <widget../> // widget #1
>
> <widget.../> // widget #1000
> </widgets>
> </order>
>
> <order>
> <widgets>
> <widget../> // widget #1001
>
> <widget.../> // widget #2000
> </widgets>
> </order>
> ...
>
> Can this be done via XSLT, or would a SAX-based solution be more
> appropriate, or?
XSLT 2.0 would be easiest and quickest to code here, but if you have
memory limitations then writing a sax based solution wouldn't to hard.
The XSLT would be something like:
<xsl:apply-templates select="/order/widgets/widget[position() mod 1000 = 1]"/>
<xsl:template match="widget">
<xsl:result-document href="...">
<order>
<widgets>
<xsl:copy-of select=".|following-sibling::widget[position() < 1000]"/>
...
cheers
--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| Re: [xsl] saxon8 running out of mem, Andrew Welch | Thread | RE: [xsl] Breaking up a large XML d, Michael Kay |
| Re: [xsl] XPath matching elements w, David Carlisle | Date | [xsl] saxon8 running out of memory, Terry Ofner |
| Month |