Note that there are some explanatory texts on larger screens.

plurals
  1. POConditionally delete Parent Node if Children nodes are empty
    primarykey
    data
    text
    <p>As the title describes I am trying to take xml like this:</p> <pre><code>&lt;Measurement&gt; &lt;Name&gt;Board_1_Output_0&lt;/Name&gt; &lt;LongIdentifier&gt;Board 1 Output 0&lt;LongIdentifier/&gt; ... &lt;ECUAddress&gt;2000000F&lt;/ECUAddress&gt; &lt;/Measurement&gt; &lt;Measurement&gt; &lt;Name/&gt; &lt;LongIdentifier/&gt; ... &lt;ECUAddress/&gt; &lt;/Measurement&gt; </code></pre> <p>and conditionally delete <code>&lt;Measurement&gt;</code> if any child nodes of <code>&lt;Measurement&gt;</code> are empty like this: </p> <pre><code>&lt;Measurement&gt; &lt;Name&gt;Board_1_Output_0&lt;/Name&gt; &lt;LongIdentifier&gt;Board 1 Output 0&lt;LongIdentifier/&gt; ... &lt;ECUAddress&gt;2000000F&lt;/ECUAddress&gt; &lt;/Measurement&gt; </code></pre> <p>My current xslt, for this section, looks like this:</p> <pre><code>&lt;xsl:for-each select="Measurement"&gt; &lt;xsl:text&gt;/begin MEASUREMENT&lt;/xsl:text&gt; &lt;xsl:text&gt;/* Name */&amp;#x09;&lt;/xsl:text&gt; &lt;xsl:value-of select ="Name"/&gt; &lt;xsl:apply-templates select="LongIdentifier"&gt; &lt;xsl:text&gt;ECU_ADDRESS&amp;#x09;&amp;#x09;&amp;#x09;&amp;#x09;&lt;/xsl:text&gt; &lt;xsl:value-of select ="ECUAddress"/&gt; &lt;xsl:text&gt;/end MEASUREMENT&lt;/xsl:text&gt; &lt;/xsl:for-each &gt;&lt;!-- Measurement --&gt; </code></pre> <p>I thought I could conditionally look at each section and not print any <code>&lt;Measurment&gt;</code> XML tags if ANY of the children tags are empty, however, I can only achieve leaving the parent <code>&lt;Measurement&gt;</code> element as such: </p> <pre><code>&lt;Measurement&gt;&lt;/Measurement&gt; </code></pre> <p>Is there a way to delete the parent xml node when I find that I have an empty child in the same xslt stylesheet? Or do I need to run the xml through a different stylesheet to delete any XML nodes that have empty children?</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.
 

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