EDN Admin
Well-known member
Hi,
Suppose I have this xml:<br/>
<br/>
<root><br/>
<node1><br/>
<node1_1 attrib1="1 <br/>
<node1_1_1 /><br/>
</node1_1><br/>
<node1_2><br/>
<node1_2_1 /><br/>
</node1_2><br/>
</node1><br/>
<node2 /><br/>
</root>
I want to remove all nodes that are empty. With this, I mean nodes that have no content and no attributes (thats it, nothing about empty attributes etc). Also very important is that nodes are removed recursively. In other words I want the result:
<root><br/>
<node1><br/>
<node1_1 attrib1="1" /><br/>
</node1><br/>
</root>
So far I have tried this basic xslt:
<xsl:template match="@*|node() <br/>
<xsl:copy><br/>
<xsl:apply-templates select="@*|node()"/><br/>
</xsl:copy><br/>
</xsl:template><br/>
<xsl:template match="*[not(child::node() | @*)]" />
This works in the sense that it removes the nodes but it does not remove them recursively. In my xml this would remove "node1_2_1" but it would NOT remove "node1_2" although it becomes empty after the deletion of "node1_2_1".<br/>
<br/>
My second problem with this xslt is that it does not provide me with a way to write a message when a node is removed. I want to have my logic negated so that I can do "<xsl:message>node removed</xsl:message>" everytime a node is removed. Of course,
Im hoping that this will work even if the recursiveness kicks in. I am using Consider that I write a <xsl:message /> when "node1_2_1" is removed but will it even be visible (as a XsltMessageEncountered event) when "node1_2_1" is removed?
I dont know yet - I need the recursivity working first...<br/>
<br/>
Can you point me in the right direction?
-- <br/>
Werner<br/>
View the full article
Suppose I have this xml:<br/>
<br/>
<root><br/>
<node1><br/>
<node1_1 attrib1="1 <br/>
<node1_1_1 /><br/>
</node1_1><br/>
<node1_2><br/>
<node1_2_1 /><br/>
</node1_2><br/>
</node1><br/>
<node2 /><br/>
</root>
I want to remove all nodes that are empty. With this, I mean nodes that have no content and no attributes (thats it, nothing about empty attributes etc). Also very important is that nodes are removed recursively. In other words I want the result:
<root><br/>
<node1><br/>
<node1_1 attrib1="1" /><br/>
</node1><br/>
</root>
So far I have tried this basic xslt:
<xsl:template match="@*|node() <br/>
<xsl:copy><br/>
<xsl:apply-templates select="@*|node()"/><br/>
</xsl:copy><br/>
</xsl:template><br/>
<xsl:template match="*[not(child::node() | @*)]" />
This works in the sense that it removes the nodes but it does not remove them recursively. In my xml this would remove "node1_2_1" but it would NOT remove "node1_2" although it becomes empty after the deletion of "node1_2_1".<br/>
<br/>
My second problem with this xslt is that it does not provide me with a way to write a message when a node is removed. I want to have my logic negated so that I can do "<xsl:message>node removed</xsl:message>" everytime a node is removed. Of course,
Im hoping that this will work even if the recursiveness kicks in. I am using Consider that I write a <xsl:message /> when "node1_2_1" is removed but will it even be visible (as a XsltMessageEncountered event) when "node1_2_1" is removed?
I dont know yet - I need the recursivity working first...<br/>
<br/>
Can you point me in the right direction?
-- <br/>
Werner<br/>
View the full article