title: split XML file by elements
body: <p>This is similar question with few differences :</p>
  
  <p><a href="https://stackoverflow.com/questions/4433529/split-xml-file-into-multiple-files-based-on-a-threshold-value">Split XML file into multiple files based on a threshold value</a></p>
  
  <p>My root element is called stores, and elements to split are called store. And I want to do this from java with xsl or without, here is my java code which I used to trigger the xsl :</p>
  
  <pre><code>public void transform(String transformator, File source, String destination) {
      try {    
          TransformerFactory tFactory = TransformerFactory.newInstance();
  
          Transformer transformer = tFactory.newTransformer(new StreamSource(transformatorLocation));
  
          try {
              transformer.transform(new StreamSource(new InputStreamReader(new FileInputStream(source), "UTF-8")), new StreamResult(new OutputStreamWriter(new FileOutputStream(destination), "UTF-8")));
          } catch (TransformerException e) {
              e.printStackTrace();
          } catch (FileNotFoundException e) {
              System.err.println("File is missing");
              e.printStackTrace();
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          }
      } catch (TransformerConfigurationException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>I've tried both solutions in this question, but they both produce erros, one is :</p>
  
  <blockquote>
    <p>ERROR:  'Unsupported XSL element '<a href="http://www.w3.org/1999/XSL/Transform:for-each-group" rel="nofollow noreferrer">http://www.w3.org/1999/XSL/Transform:for-each-group</a>''
        javax.xml.transform.TransformerException: java.lang.RuntimeException: Unsupported XSL element '<a href="http://www.w3.org/1999/XSL/Transform:for-each-group" rel="nofollow noreferrer">http://www.w3.org/1999/XSL/Transform:for-each-group</a>'</p>
  </blockquote>
  
  <p>Other is that style sheet can't be compiled. </p>
  
  <p>What I try to accomplish ? Pass argument to java class how many stores do I want in one file, and split it into n parts.</p>