title: Remove child element based on some attribute criteria of child element xslt 1
body: <p>I need to remove the child element on the bases of the value of an id attribute. If there is no value in id attribute or there is no id attribute at all in contentblock tag then just remove the  element and parent element will remain same if present. Also if content block is direct child of root and that content block doesn't have value in id attribute or there is no id attribute then remove that element also.</p>
  <p>Example:</p>
  <pre><code>&lt;root&gt;
   &lt;div&gt;
     &lt;contentblock class=&quot;align-center&quot; id=&quot;&quot; /&gt;
  &lt;/div&gt;
   &lt;p&gt;
     &lt;contentblock class=&quot;align-center&quot; /&gt;
  &lt;/p&gt;
   &lt;h2&gt;
     &lt;contentblock class=&quot;align-center&quot; id=&quot;623a7a1f87dd1975ce084ac7&quot;/&gt;
  &lt;/h2&gt;
  &lt;contentblock class=&quot;align-center&quot; id=&quot;&quot;/&gt;
  &lt;contentblock class=&quot;align-center&quot; id=&quot;623a7a1f87dd1975ce084ac7&quot;/&gt;
  &lt;contentblock class=&quot;align-center&quot;/&gt;
  &lt;/root&gt;
  </code></pre>
  <p>Expected Result:</p>
  <pre><code>&lt;root&gt;
   &lt;div&gt;
   &lt;/div&gt;
   &lt;p&gt;
  &lt;/p&gt;
   &lt;h2&gt;
     &lt;contentblock class=&quot;align-center&quot; id=&quot;623a7a1f87dd1975ce084ac7&quot;/&gt;
  &lt;/h2&gt;
  &lt;contentblock class=&quot;align-center&quot; id=&quot;623a7a1f87dd1975ce084ac7&quot;/&gt;
  &lt;/root&gt;
  </code></pre>
  <p>Thanks in advance for the help.</p>
  <p>What i tried but didn't give the expected result:</p>
  <pre><code> &lt;!--&lt;xsl:template match=&quot;contentblock[not(parent::root)] | contentblock[(parent::root)]&quot;&gt;--&gt;
          &lt;!--&lt;xsl:choose&gt;--&gt;
      &lt;!--      &lt;xsl:if test=&quot;contentblock/@id[string-length(.) =0]&quot;&gt;--&gt;
      &lt;!--            &lt;xsl:apply-templates/&gt;--&gt;
      &lt;!--      &lt;/xsl:if&gt;--&gt;
          &lt;!--&lt;/xsl:choose&gt;--&gt;
      &lt;!--&lt;/xsl:template&gt;--&gt;
  </code></pre>
  <p>Another try:</p>
  <pre><code> &lt;xsl:template match=&quot;div[contentblock] | p[descendant::contentblock] | h2[descendant::contentblock] | h3[descendant::contentblock]&quot;&gt;
          &lt;xsl:choose&gt;
            &lt;xsl:when test=&quot;contentblock[@id!='']&quot;&gt;
                      &lt;xsl:apply-templates/&gt;
            &lt;/xsl:when&gt;
          &lt;/xsl:choose&gt;
           &lt;xsl:choose&gt;
            &lt;xsl:when test=&quot;contentblock[@id=''] | contentblock[not(@id)]&quot;&gt;
          &lt;xsl:copy&gt; &lt;xsl:apply-templates select=&quot;@*&quot;/&gt;&lt;/xsl:copy&gt;
            &lt;/xsl:when&gt;
          &lt;/xsl:choose&gt;
      &lt;/xsl:template&gt;
  </code></pre>
  <p>I can't match  <code>&lt;xsl:template match=&quot;contentblock[not(parent::root)]&quot;&gt;</code> as it performs the transformation on content block element itself which gives  me different result. And also above solution does not work when i get the xml like this. When contentblock have multiple level parents like here it's p and span are parents of contentblock.</p>
  <pre><code> &lt;p id=&quot;5c3692c8af8fe1f061518abc&quot;&gt;
        &lt;span bulb-font-face=&quot;museo-sans, sans-serif&quot;&gt;
           &lt;contentblock class=&quot;align-center block-full-width&quot; id=&quot;5c3686fdcb7de304cd51696f&quot; /&gt;
        &lt;/span&gt;
     &lt;/p&gt;
  
    
  </code></pre>