I am having some output problems with xslt files in umbraco. All html tags without any content (left intentionally empty) are being rendered as shorttags.
Example:
<div class="'someClass"></div>
is being rendered
<div class="'someClass"/>
I tried changing the xsl output method to html but that causes another problem. The shorttags are having the ending slash ("/") stripped.
Example:
<img src="#" alt="" />
is being rendered
<img src="#" alt="">
Does anyone have an elegant solution for this problem.
This is the curse of Microsoft's XSLT processor; Problem is, it's not really violating the spec (in XML there is no difference between the long and the short version of an empty element, and in HTML some tags are required not to have a closing tag) so what cab we do?
Personally, I use "xml" mode and test for non-empty content before writing an element that could be rendered empty, e.g.:
This allows for literal mark-up... the XSLT processor will just output it as is. Sure, it looks long-winded, but that's just the super-long "disable-out-escaping" attribute, (which we all would agree is ugly as sin!!)
Alternatively, go with "html" output and change your doc-type to HTML4 ... nothing "wrong" with it, it's just dated and we everyone feels that XHTML is purer.
XSLT output not valid as xhtml 1.0 transitional
Hi there,
I am having some output problems with xslt files in umbraco. All html tags without any content (left intentionally empty) are being rendered as shorttags.
Example:
<div class="'someClass"></div>
is being rendered
<div class="'someClass"/>
I tried changing the xsl output method to html but that causes another problem. The shorttags are having the ending slash ("/") stripped.
Example:
<img src="#" alt="" />
is being rendered
<img src="#" alt="">
Does anyone have an elegant solution for this problem.
Cheers,
What happens if you do the following
Damn it stripped the text - I wonder if this will work
Hi Bogdan,
This is the curse of Microsoft's XSLT processor; Problem is, it's not really violating the spec (in XML there is no difference between the long and the short version of an empty element, and in HTML some tags are required not to have a closing tag) so what cab we do?
Personally, I use "xml" mode and test for non-empty content before writing an element that could be rendered empty, e.g.:
<xsl:if test="normalize-space(.)"> <div class="someClass"><xsl:value-of select="." /></div> </xsl:if>
- But you can always put an empty comment inside an element to force generation of a closetag:
- which will output as:
Hope that helps,
/Chriztian
It's always a good idea to test if there is any content like Chriztian is mentioning. Empty tags in the source code does not make any sense! :)
/Jan
<div class="someClass"> </div>
Yes, this is annoying "feature" especially when adding <script src="somthign.js"> because in IE whole pages gets empty.
I do the same has Jorge suggest above, just add  
Not very beatiful but works.
i use <xsl:text> </xsl:text> inside any empty elements, makes for a bit cleaner markup inside the xslt, and renders a space in the output xhtml.
Hi Bogdan,
As you guess, the MS-XML processor is working correctly ... by self-closing the empty tags (in XML mode).
Following on from Chriztian's suggestions, I prefer the following XSLT:
This allows for literal mark-up... the XSLT processor will just output it as is. Sure, it looks long-winded, but that's just the super-long "disable-out-escaping" attribute, (which we all would agree is ugly as sin!!)
Alternatively, go with "html" output and change your doc-type to HTML4 ... nothing "wrong" with it, it's just dated and we everyone feels that XHTML is purer.
Cheers, Lee.
Hey all,
First of all thanks for your quick replies. So far I'll go with Chriztian Steinmeier's solutio:
It's the cleanest one so far in my opinion.
@Jan Skovgaard: I agree with you about empty tags, but in this particular case the tags are used for page layout only.
Thanks everyone for your input on this. If someone out there is got an even better solution I'm more than happy to hear it.
Cheers,
Bogdan
is working on a reply...