title: Use xml_split to split an XML file based on a Perl regex or XPath expression
body: <p>I have a huge XML file that I want to split into chunks based on the product type attribute.</p>
  
  <p>I don't know how to use XSLT. I found <a href="https://metacpan.org/pod/release/MIROD/XML-Twig-3.49/tools/xml_split/xml_split" rel="nofollow"><code>xml_split</code></a> but can't figure out how to use it with a regex or XPath to split the document depending on the type attribute</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!DOCTYPE catalog SYSTEM "catalog.dtd"&gt;
  &lt;catalog&gt;
     &lt;product type="cloths" product_image="cardigan.jpg"&gt;
        &lt;catalog_item gender="Men's"&gt;
           &lt;item_number&gt;QWZ5671&lt;/item_number&gt;
           &lt;price&gt;39.95&lt;/price&gt;
           &lt;size description="Medium"&gt;
              &lt;color_swatch image="red_cardigan.jpg"&gt;Red&lt;/color_swatch&gt;
              &lt;color_swatch image="burgundy_cardigan.jpg"&gt;Burgundy&lt;/color_swatch&gt;
           &lt;/size&gt;
           &lt;size description="Large"&gt;
              &lt;color_swatch image="red_cardigan.jpg"&gt;Red&lt;/color_swatch&gt;
              &lt;color_swatch image="burgundy_cardigan.jpg"&gt;Burgundy&lt;/color_swatch&gt;
           &lt;/size&gt;
        &lt;/catalog_item&gt;
        &lt;catalog_item gender="Women's"&gt;
           &lt;item_number&gt;RRX9856&lt;/item_number&gt;
           &lt;price&gt;42.50&lt;/price&gt;
           &lt;size description="Small"&gt;
              &lt;color_swatch image="red_cardigan.jpg"&gt;Red&lt;/color_swatch&gt;
              &lt;color_swatch image="navy_cardigan.jpg"&gt;Navy&lt;/color_swatch&gt;
              &lt;color_swatch image="burgundy_cardigan.jpg"&gt;Burgundy&lt;/color_swatch&gt;
           &lt;/size&gt;
           &lt;size description="Medium"&gt;
              &lt;color_swatch image="red_cardigan.jpg"&gt;Red&lt;/color_swatch&gt;
              &lt;color_swatch image="navy_cardigan.jpg"&gt;Navy&lt;/color_swatch&gt;
              &lt;color_swatch image="burgundy_cardigan.jpg"&gt;Burgundy&lt;/color_swatch&gt;
              &lt;color_swatch image="black_cardigan.jpg"&gt;Black&lt;/color_swatch&gt;
           &lt;/size&gt;
           &lt;size description="Large"&gt;
              &lt;color_swatch image="navy_cardigan.jpg"&gt;Navy&lt;/color_swatch&gt;
              &lt;color_swatch image="black_cardigan.jpg"&gt;Black&lt;/color_swatch&gt;
           &lt;/size&gt;
           &lt;size description="Extra Large"&gt;
              &lt;color_swatch image="burgundy_cardigan.jpg"&gt;Burgundy&lt;/color_swatch&gt;
              &lt;color_swatch image="black_cardigan.jpg"&gt;Black&lt;/color_swatch&gt;
           &lt;/size&gt;
        &lt;/catalog_item&gt;
     &lt;/product&gt;
  &lt;/catalog&gt;
  </code></pre>
  
  <p>I used this command</p>
  
  <pre><code>xml_split -c /catalog/product[@type='cloths'] products.xml
  </code></pre>
  
  <p>but it reproduces the complete XML document without the XPath filtering.</p>