xsl-list
[Top] [All Lists]

Re: [xsl] is there any XSL Splitter to split XML in 200 chunk of record

2017-07-12 14:19:47
On 07/12/2017 10:52 AM, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de 
wrote:
Do you want to create several result files, each containing a certain
number of records? Or simply one file where you wrap a certain number of
records?

I think he means the latter, grouping 200 <name> elements at a time and
(in effect) splitting the <optical> container between the 200th and
201st <name> element, between the 400th and 401st, etc. The result tree
would then be serialised inside a new <opticals> root element.

///Peter



In any way, assuming XSLT 2.0, you can use positional grouping e.g.


<xsl:for-each-group select="/optical/name" group-by="(position() - 1)
idiv 200">

   <xsl:result-document select="result{position()}.xml">

    <optical>

     <xsl:copy-of select="current-group()"/>

  </optical>

  </xsl:result-document>

</xsl:for-each-group>


Am 12.07.2017 um 11:11 schrieb Rahul Singh 
rahulsinghindia15(_at_)gmail(_dot_)com:
Hi,

Is there any posiblites in XSL to split XML in 200  200 chunk of
record in same xml by xsl, *below is inputm expected putput, xsl:*

<?xml version="1.0" encoding="UTF-8"?>
<optical>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
</optical>

*Expected output:*

<?xml version="1.0" encoding="UTF-8"?>
<opticals>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
</optical>
<optical>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
  <name>
    <Doc>log00.txt</Doc>
  </name>
</optical>
</opticals>
*
*
*XSL:*
*
*
*
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
    <xsl:output omit-xml-declaration="yes" indent="yes"/>
    <xsl:template match="optical">
        <xsl:for-each select="name/Doc">
            <xsl:copy-of select="."/>
                <xsl:if test="not(position() eq last())">
                </xsl:if>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

*

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/582271> (by email)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/2554186>
(by email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>