title: XSLT split output files - muenchian grouping
body: <p>I have an XSLT file so as to transform large amount of data. I would like to add a "split" functionality, either as a chained XSLT or within the current XSLT that can create multiple output files so as to limit the size of the files under a certain threshold.
  Let's assume that the input XML is as below:</p>
  
  <pre><code>&lt;People&gt;
  &lt;Person&gt;             
  &lt;name&gt;John&lt;/name&gt;             
  &lt;date&gt;June12&lt;/date&gt;             
  &lt;workTime taskID="1"&gt;34&lt;/workTime&gt;             
  &lt;workTime taskID="2"&gt;12&lt;/workTime&gt;             
  &lt;/Person&gt;             
  &lt;Person&gt;             
  &lt;name&gt;John&lt;/name&gt;             
  &lt;date&gt;June13&lt;/date&gt;             
  &lt;workTime taskID="1"&gt;21&lt;/workTime&gt;             
  &lt;workTime taskID="2"&gt;11&lt;/workTime&gt;             
  &lt;/Person&gt;
  &lt;Person&gt;             
  &lt;name&gt;Jack&lt;/name&gt;             
  &lt;date&gt;June19&lt;/date&gt;             
  &lt;workTime taskID="1"&gt;20&lt;/workTime&gt;             
  &lt;workTime taskID="2"&gt;30&lt;/workTime&gt;             
  &lt;/Person&gt;    
  &lt;/People&gt;
  </code></pre>
  
  <p>The XSLT file is as below using muenchian grouping.</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:key name="PersonTasks" match="workTime" use="concat(@taskID, ../name)"/&gt;
  &lt;xsl:template match="/"&gt;
      &lt;People&gt;
      &lt;xsl:apply-templates select="//workTime[generate-id() = generate-id(key('PersonTasks',concat(@taskID, ../name))[1])]"/&gt;
      &lt;/People&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="workTime"&gt;
      &lt;xsl:variable name="taskID"&gt;
          &lt;xsl:value-of select="@taskID"/&gt;
      &lt;/xsl:variable&gt;
      &lt;xsl:variable name="name"&gt;
          &lt;xsl:value-of select="../name"/&gt;
      &lt;/xsl:variable&gt;
      &lt;Person&gt;
          &lt;name&gt;
              &lt;xsl:value-of select="$name"/&gt;
          &lt;/name&gt;
          &lt;taskID&gt;
              &lt;xsl:value-of select="$taskID"/&gt;
          &lt;/taskID&gt;
          &lt;xsl:for-each select="//workTime[../name = $name][@taskID = $taskID]"&gt;
              &lt;workTime&gt;
                  &lt;date&gt;
                      &lt;xsl:value-of select="../date"/&gt;
                  &lt;/date&gt;
                  &lt;time&gt;
                      &lt;xsl:value-of select="."/&gt;
                  &lt;/time&gt;
              &lt;/workTime&gt;
          &lt;/xsl:for-each&gt;
      &lt;/Person&gt;
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>However, I'd like ,as an output, several files as below instead of a large one. For this example, I have set only one name per file..but this should be a parameter.</p>
  
  <p>Output file for first person:</p>
  
  <pre><code>&lt;People&gt;
      &lt;Person&gt;
          &lt;name&gt;John&lt;/name&gt;
          &lt;taskID&gt;1&lt;/taskID&gt;
          &lt;workTime&gt;
          &lt;date&gt;June12&lt;/date&gt;
          &lt;time&gt;34&lt;/time&gt;
          &lt;/workTime&gt;
          &lt;workTime&gt;
          &lt;date&gt;June13&lt;/date&gt;
          &lt;time&gt;21&lt;/time&gt;
          &lt;/workTime&gt;
      &lt;/Person&gt;
      &lt;Person&gt;
          &lt;name&gt;John&lt;/name&gt;
          &lt;taskID&gt;2&lt;/taskID&gt;
          &lt;workTime&gt;
          &lt;date&gt;June12&lt;/date&gt;
          &lt;time&gt;12&lt;/time&gt;
          &lt;/workTime&gt;
          &lt;workTime&gt;
          &lt;date&gt;June13&lt;/date&gt;
          &lt;time&gt;11&lt;/time&gt;
          &lt;/workTime&gt;
      &lt;/Person&gt;
  &lt;/People&gt;
  </code></pre>
  
  <p>Output file for second person:</p>
  
  <pre><code>&lt;People&gt;
      &lt;Person&gt;
          &lt;name&gt;Jack&lt;/name&gt;
          &lt;taskID&gt;1&lt;/taskID&gt;
          &lt;workTime&gt;
          &lt;date&gt;June19&lt;/date&gt;
          &lt;time&gt;20&lt;/time&gt;
          &lt;/workTime&gt;
      &lt;/Person&gt;
      &lt;Person&gt;
          &lt;name&gt;Jack&lt;/name&gt;
          &lt;taskID&gt;2&lt;/taskID&gt;
          &lt;workTime&gt;
          &lt;date&gt;June19&lt;/date&gt;
          &lt;time&gt;30&lt;/time&gt;
          &lt;/workTime&gt;
      &lt;/Person&gt;
  &lt;/People&gt;
  </code></pre>
  
  <p>What would be the preferred and most elegant approach using XSLT 1.0? Is there a way to call a chained XSLT within the XSLT so as to split the output files?</p>
  
  <p>Cheers.</p>