I'm not an XSLT wizard.
I have the current XSLT i'm using to remove empty nodes:
string strippingStylesheet = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
"<xsl:template match=\"@*|node()\">" +
"<xsl:if test=\". != ''\">" +
"<xsl:copy>" +
"<xsl:apply-templates select=\"@*|node()\"/>" +
"</xsl:copy>" +
"</xsl:if></xsl:template></xsl:stylesheet>";
I need to find a way to also remove nodes with -1 in them. A previous developer thought it would be a good idea to make every int in the system be defaulted to -1, and yes that means all DB fields have -1 in them instead of null.
So as much as I want to beat the dead horse (with a stick, bat, bazooka), I need to get back to work and get this done.
Any help would be great.
I guess that it is required to remove all "empty nodes".
The processing depends on the definition of "empty node". One reasonable definition in your case is: Any element that doesn't have attributes and children or doesn't have attributes and has only one child that is a text node with value
-1
.For this definition here is a simple solution.
This transformation:
when applied on this sample XML document:
produces the wanted, correct result:
In simple case this should work:
With this simple input:
Result will be: