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

RE: Breaking up a large XML document into several smal

Subject: RE: Breaking up a large XML document into several smaller ones
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 12 Jan 2008 08:42:04 -0000
RE:  Breaking up a large XML document into several smal
A SAX solution would execute faster and in less memory but would take rather
longer to write.

It's not difficult in XSLT 2.0

<xsl:for-each-group select="widget" group-by="(position()-1) idiv 1000">
  <xsl:result-document href="widgets{position()}.xml">
    <widgets>
      <xsl:copy-of select="current-group()"/>
    </widgets>
  </xsl:result-document>
</xsl:for-each-group>

Michael Kay
http://www.saxonica.com/

 

> -----Original Message-----
> From: Glen Mazza [mailto:glen.mazza@xxxxxxxxx] 
> Sent: 11 January 2008 14:49
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Breaking up a large XML document into several 
> smaller ones
> 
> 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?
> 
> Thanks,
> Glen

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.