Question

I've got some XML files that recently changed so that some of the nodes now have the attribute xsi:nil="true". I've got an XSLT style sheet that renders the XML into HTML for some quick eyeballing of data. Currently to make things easier on myself I strip out the namespaces out of the XML before I apply the style sheet. That worked fine up till our last update. Now I'm getting an error because the XSL doesn't know how to handle the xsl:nil="true".

I can easily update the code so I do a replace/remove on all the xsl:nil="true" matches in the XML before I transform it, but I was wondering if it is possible to cludge the XSLT style sheet so that xsi:nil's will be ignored/not cause transformation failures even if no namespaces are including in the XML. I would prefer to do things this way because I can make the change on the server now, where if I have to issue a new web build I have to jump through some internal hoops to get it deployed.

After I get things working (either through removing the xsl:nil's before or during the transformation) I'll circle back around and figure out why I removed the namespaces originally and fix that.

Thanks for any help you can give me.

Was it helpful?

Solution

Why did you remove the namespaces in the first place? The XSLT lets you control what prefixes shall not be put into the output, and you can skip those xsi:nil nicely in the stylesheet.

If there is no namespace prefix declaration for the xsi prefix, the XML is not valid. So either you are dealing with invalid XML or you still have some XSI namespace declaration somewhere, and you could change the XSLT to skip those entries.

If you do a find-replace on the XML source, really make sure to fix it later (soon!), because this kind of stuff is going to break your neck.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top