Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation</strong>:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="node()|@*"&gt; &lt;xsl:copy&gt; &lt;xsl:apply-templates select="node()|@*"/&gt; &lt;/xsl:copy&gt; &lt;/xsl:template&gt; &lt;xsl:template match="ntig[not(*/term[string-length()&gt;0])]"/&gt; &lt;xsl:template match="langSet[not(*/*/term[string-length()&gt;0])]"/&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document</strong>:</p> <pre><code>&lt;body&gt; &lt;termEntry id="1"&gt; &lt;langSet lang="eng-us"&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;/langSet&gt; &lt;langSet lang="ara-ae"&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;123&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;/langSet&gt; &lt;/termEntry&gt; &lt;termEntry id="2"&gt; &lt;langSet lang="eng-us"&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;123&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;/langSet&gt; &lt;/termEntry&gt; &lt;/body&gt; </code></pre> <p><strong>produces the wanted result</strong>:</p> <pre><code>&lt;body&gt; &lt;termEntry id="1"&gt; &lt;langSet lang="ara-ae"&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;123&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;/langSet&gt; &lt;/termEntry&gt; &lt;termEntry id="2"&gt; &lt;langSet lang="eng-us"&gt; &lt;ntig&gt; &lt;termGrp&gt; &lt;term&gt;123&lt;/term&gt; &lt;/termGrp&gt; &lt;/ntig&gt; &lt;/langSet&gt; &lt;/termEntry&gt; &lt;/body&gt; </code></pre> <p><strong>Explanation</strong>:</p> <ol> <li><p>The identity rule (template) copies every node "as-is".</p></li> <li><p>The template overriding the identity rule for <code>ntig[not(*/term[string-length()&gt;0])]</code> has an empty body -- this effectively ignores (deletes) any <code>ntig</code> element that doesn't have at lest one <code>term</code> grandchild with positive <code>string-length()</code>.</p></li> <li><p>The template overriding the identity rule for <code>langSet[not(*/*/term[string-length()&gt;0])]</code> has an empty body -- this effectively ignores (deletes) any <code>langSet</code> element that doesn't have at lest one <code>term</code> great-grandchild with positive <code>string-length()</code>.</p></li> </ol> <p><strong>Do note</strong> that specifying templates like this violates the definition of the problem:</p> <pre><code>&lt;xsl:template match="ntig[descendant::term[. = '']]"/&gt; &lt;xsl:template match="langSet[not(descendant::term[. != ''])]"/&gt; </code></pre> <p>Because the requirement is to "if the value in is null\empty, delete its <em>grandparent</em> node". </p> <p>However, the first template above deletes not only the grand-parent <code>ntig</code>, but <em>any ancestor</em> <code>ntig</code>.</p> <p><strong>The current solution does not commit such a mistake</strong>.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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