I created an XSLT to render a Call To Action side bar that is on every page. In the markup I have the following:
<div class="Whatever"></div>
The xslt file saves fine, but when rendered on the page, the </div> is removed and kills the whole page layout. I did a little digging and ended up adding in between the tags, which corrects the problem, but I am wondering why the </div> is being removed.
If you are using <xsl:output method="xml"> you must ensure that elements not might be empty and prevent tags from being self-closing.. unfortunately some odd places in the markup, which might break the layout..
There are different approach to solve this.
A way I often use is adding <xsl:text> between the tags to force a space so the element isn't empty .. : <div class="Whatever"><xsl:text> </xsl:text></div>
XSLT removes </div> and kills layout
Hello!
I created an XSLT to render a Call To Action side bar that is on every page. In the markup I have the following:
<div class="Whatever"></div>
The xslt file saves fine, but when rendered on the page, the </div> is removed and kills the whole page layout. I did a little digging and ended up adding in between the tags, which corrects the problem, but I am wondering why the </div> is being removed.
Any insight to this would be great!.
Phillip
Well... seems like I enjoy answering my own questions.
The problem is the output method in the XSLT file. By default, it set to XML, which will remove those closing tags if no content is there:
<xsl:output method="xml">
Changing this to HTML fixes the problem.
<xsl:output method="html">
;o)
Hi Phillip
If you are using <xsl:output method="xml"> you must ensure that elements not might be empty and prevent tags from being self-closing.. unfortunately some odd places in the markup, which might break the layout..
There are different approach to solve this.
A way I often use is adding <xsl:text> between the tags to force a space so the element isn't empty .. : <div class="Whatever"><xsl:text> </xsl:text></div>
There are other ways to overcome this issue, see this wiki: http://our.umbraco.org/wiki/how-tos/xslt-useful-tips-and-snippets/stop-html-tags-from-self-closing
/Bjarne
Hi Phillip,
Another way of doing this would be
@Fuji that doesn't make sense :)
If you choose that approach it should be:
@Bjarne Exactly what the second threat was supposed to display instead of that a blank post :)
Weird I did modify the code in the second post when realized i used attribute for div instead of element.
is working on a reply...