CodeGarden 10: The sixth annual Umbraco Developer Conference
June 23-25th 2010 - free ASP.NET MVC pre-conference. Register today!

Stop HTML tags from self-closing

If your HTML requires a non-self-closing HTML tag which has no content between the opening and closing tag like this:

<span class="overlay"></span>

Then you will find that if you put the above in an XSLT it will get transformed to:

<span class="overlay" />

Which may not display as expected in your browser.

To get the correct code to be output you can do one of the following:

<span class="overlay"><xsl:text> </xsl:text></span>

<span class="overlay"><xsl:value-of select="''"/></span>

<xsl:text disable-output-escaping="yes">&lt;span class="overlay"&gt;&lt;/span&gt;</xsl:text>

<xsl:text disable-output-escaping="yes"><![CDATA[<span class="overlay"></span>]]></xsl:text>

Another solution is to use <xsl:comment>

<span class="overlay"><xsl:comment></xsl:comment></span>

 

Another approach is to change the output to html

<xsl:output method="html" omit-xml-declaration="yes"/>