XSLT self-closing tags issue
Solution 1
If you are using XmlWriter as your ouput stream, use HTMLTextWriter instead. XMLWriter will reformat your HTML output back to XML.
Solution 2
Change your xsl:output
method to be html
(instead of xml
).
Or add it if you haven't already got the element
<xsl:output method="html"/>
Solution 3
A workaround can be to insert a comment element to force generation of non self closing:
<script type="text/javascript" src="nowhere.js">
<xsl:comment></xsl:comment>
</script>
It is not a pretty soloution, but it works :-)
/Sten
Solution 4
This is related to the XslCompiledTransform class
here is a workaround:
Solution 5
For me it was a problem in the script tag. I solved it by filling it with a semicolon (;)
<script type="text/javascript" src="somewhere.js">;</script>
Admin
Updated on March 03, 2020Comments
-
Admin about 4 years
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.