I am using xslt to transform an xml file to html. The .net xslt engine keeps serving me self-closing tags for empty tags.
Example:
<div class="test"></div>
becomes
<div class="test" />
The former is valid html, while the latter is illegal html and renders badly. My question is : How do I tell the xslt engine (XslCompiledTransform) to not use self-closing tags.
If it's not possible, how can I tell my browser (IE6+ in this case) to interpret self-closing tags correctly.
A workaround can be to insert a comment element to force generation of non self closing:
It is not a pretty soloution, but it works :-)
/Sten
I used to put an
<xsl:text>
element inside, like:I use the following whenever I wish to prevent an element from self-closing:
This fools the rendering engine into believe there is content inside the element, and therefore prevents self-closure.
It's a bit of an ugly fix so I recommend containing it in a descriptive template and calling that each time instead:
This will then render the following:
http://curtistimson.co.uk/post/xslt/how-to-prevent-self-closing-elements-in-xslt/
Just experienced the same issue with PHP 5's XSL, with output/@method=html. Seems that assigning an empty value attribute will cause elements to be output as invalid non-self-closing, non-closed tags:
results in:
One possible solution is to conditionally add the attribute:
resulting in:
For me it was a problem in the script tag. I solved it by filling it with a semicolon (;)
This is related to the XslCompiledTransform class
here is a workaround:
http://blogs.msdn.com/b/nareshjoshi/archive/2009/01/15/how-to-force-non-self-closing-tags-for-empty-nodes-when-using-xslcompiledtransform-class.aspx