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

Splitting files 5 at a time

Subject: Splitting files 5 at a time
From: "Danny Leblanc" <leblancd@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 2 Apr 2008 14:08:14 -0400
 Splitting files 5 at a time
Hello everyone,

  I currently have the following XSLT code.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="DATA_FILE/CUSTOMER">
         <xsl:result-document
href="{FOLDER}{format-number(position(),'000000000')}.xml">
          <DATA_FILE>
              <xsl:apply-templates select="."/>
          </DATA_FILE>
         </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
  <xsl:template match="@*|node()">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>

  This works perfectly and splits the XML input file per CUSTOMER. Now I
am being asked to split the XML file but instead of having 1 customer
per output file I am not being asked to split it down with 5 CUSTOMERS
per "new" output file. (And the last split must work even if there is
not a multiple of 5 CUSTOEMERS in the file).

  I have played with the for-each since I won't need a loop iteration
per CUSTOMER anymore but 1 per 5 so I tried something like

<xsl:for-each select="DATA_FILE/CUSTOMER[count() mod 5 = 0">

  But this did not work. I am certain I will have to change the
apply-templates as well but I have not even gotten to that point yet.

  Can you please let me know if I am going in the right direction here?
Any and all help is welcome.

Thank you.

P.S if you try and run the code, {FOLDER} will have to be replaced. This
is run inside of an application that calls an XSLT engine and the
{FOLDER} is replaced by the temp folder where the files are stored as
they are processed.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.