Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made good experiences with <a href="http://stx.sourceforge.net/" rel="nofollow noreferrer">STX</a> (<strong>Streaming Transformations for XML</strong>). Basically, it is a streamed version of XSLT, well suited to parsing huge amounts of data with minimal memory footprint. It has an implementation in Java named <a href="http://joost.sourceforge.net/" rel="nofollow noreferrer">Joost</a>.</p> <p>It should be easy to come up with a STX transform that ignores all elements until the element matches a given XPath, copies that element and all its children (using an identity template within a template group), and continues to ignore elements until the next match.</p> <p><strong>UPDATE</strong></p> <p>I hacked together a STX transform that does what I understand you want. It mostly depends on STX-only features like template groups and configurable default templates.</p> <pre><code>&lt;stx:transform xmlns:stx="http://stx.sourceforge.net/2002/ns" version="1.0" pass-through="none" output-method="xml"&gt; &lt;stx:template match="element/child"&gt; &lt;stx:process-self group="copy" /&gt; &lt;/stx:template&gt; &lt;stx:group name="copy" pass-through="all"&gt; &lt;/stx:group&gt; &lt;/stx:transform&gt; </code></pre> <p>The <code>pass-through="none"</code> at the <code>stx:transform</code> configures the default templates (for nodes, attributes etc.) to produce no output, but process child elements. Then the <code>stx:template</code> matches the XPath <code>element/child</code> (this is the place where you put your match expression), it "processes self" in the "copy" group, meaning that the matching template from the <code>group name="copy"</code> is invoked on the current element. That group has <code>pass-though="all"</code>, so the default templates copy their input and process child elements. When the <code>element/child</code> element is ended, control is passed back to the template that invoked <code>process-self</code>, and the following elements are ignored again. Until the template matches again.</p> <p>The following is an example input file:</p> <pre><code>&lt;root&gt; &lt;child attribute="no-parent, so no copy"&gt; &lt;/child&gt; &lt;element id="id1"&gt; &lt;child attribute="value1"&gt; text1&lt;b&gt;bold&lt;/b&gt; &lt;/child&gt; &lt;/element&gt; &lt;element id="id2"&gt; &lt;child attribute="value2"&gt; text2 &lt;x:childX xmlns:x="http://x.example.com/x"&gt; &lt;!-- comment --&gt; yet more&lt;b i="i" x:i="x-i" &gt;&lt;/b&gt; &lt;/x:childX&gt; &lt;/child&gt; &lt;/element&gt; &lt;/root&gt; </code></pre> <p>This is the corresponding output file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;child attribute="value1"&gt; text1&lt;b&gt;bold&lt;/b&gt; &lt;/child&gt;&lt;child attribute="value2"&gt; text2 &lt;x:childX xmlns:x="http://x.example.com/x"&gt; &lt;!-- comment --&gt; yet more&lt;b i="i" x:i="x-i" /&gt; &lt;/x:childX&gt; &lt;/child&gt; </code></pre> <p>The unusual formatting is a result of skipping the text nodes containing newlines outside the <code>child</code> elements.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload