I'm trying to split an xml input document for every 5 elements. Using the below sample input doc, I would like to split it for every 5 JournalEntry elements. I've also provided a sample output document.
XML Input
<?xml version="1.0" encoding="UTF-8"?>
<JournalFileData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:js="urn:com.journal/JournalSource" js:Add="false">
<AccountingData>
<Locked>0</Locked>
<Company js:type="Organization_Reference_ID">Some Company</Company>
<Currency>USD</Currency>
<Ledger>ACTUALS</Ledger>
<Date>12-15-2021</Date>
<Journal>Manual</Journal>
<JournalEntry>
<LineCompany js:type="Company">Widget Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<CreditAmount>100</CreditAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Global Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Company">JAG Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Resource Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Supply Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Company">Plain Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Gnome Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
</AccountingData>
</JournalFileData>
XML Output
<?xml version="1.0" encoding="UTF-8"?>
<FileList>
<File>
<JournalFileData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:js="urn:com.journal/JournalSource" js:Add="false">
<AccountingData>
<Locked>0</Locked>
<Company js:type="Organization_Reference_ID">Some Company</Company>
<Currency>USD</Currency>
<Ledger>ACTUALS</Ledger>
<Date>12-15-2021</Date>
<Journal>Manual</Journal>
<JournalEntry>
<LineCompany js:type="Company">Widget Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<CreditAmount>100</CreditAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Global Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Company">JAG Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Resource Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
</AccountingData>
</JournalFileData>
</File>
<File>
<JournalFileData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:js="urn:com.journal/JournalSource" js:Add="false">
<AccountingData>
<Locked>0</Locked>
<Company js:type="Organization_Reference_ID">Some Company</Company>
<Currency>USD</Currency>
<Ledger>ACTUALS</Ledger>
<Date>12-15-2021</Date>
<Journal>Manual</Journal>
<JournalEntry>
<LineCompany js:type="Company">Plain Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">1000</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
<JournalEntry>
<LineCompany js:type="Organization">Gnome Company</LineCompany>
<LedgerAccount js:type="Ledger_Account_ID">9999</LedgerAccount>
<DebitAmount>100</DebitAmount>
<Currency>USD</Currency>
</JournalEntry>
</AccountingData>
</JournalFileData>
</File>
</FileList>
Here is my last xslt attempt (Please excuse any typos. I had to type this out). I've had various results but none have gotten me the output I need. I'm having trouble finding the correct syntax to get the format outlined in the xml output. Also having trouble trying to copy the child nodes for each AccountingData node. I don't work with xslt frequent enough and still consider myself a novice so any help is appreciated. This is just my last try.:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:js="urn:com.journal/JournalSource" js:Add="false"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="JournalFileData/AccountingData">
<FileList>
<xsl:copy>
<xsl:for-each-group select="JournalEntry" group-adjacent="(position() -1) idiv 5">
<File>
<JournalFileData xmlns:js="urn:com.journal/JournalSource" js:Add="false">
<AccountingData>
<xsl:copy-of select="current-group()"/>
</AccountingData>
</JournalFileData>
</File>
</xsl:for-each-group>
</xsl:copy>
</FileList>
</xsl:template>
</xsl:stylesheet>