Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


[xsl] Splitting files 5 at a time

From: "Danny Leblanc" <leblancd@------------------->
To:
Date: 4/2/2008 6:09:00 PM
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.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent