Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Phillip Turner 98 posts 412 karma points
    Feb 21, 2014 @ 19:03
    Phillip Turner
    0

    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 &nbsp; 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

  • Phillip Turner 98 posts 412 karma points
    Feb 21, 2014 @ 19:11
    Phillip Turner
    100

    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)

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 21, 2014 @ 19:45
    Bjarne Fyrstenborg
    0

    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

  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 21, 2014 @ 23:32
    Fuji Kusaka
    0

    Hi Phillip,

    Another way of doing this would be 

    <xsl:attribute name ="div">
    <xsl:element name="class">
    <xsl:text>whatever</xsl:text> 
    </xsle:element>
    </xsl:attribute> 
  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 21, 2014 @ 23:33
    Fuji Kusaka
    0
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 22, 2014 @ 00:21
    Bjarne Fyrstenborg
    1

    @Fuji that doesn't make sense :)

    If you choose that approach it should be:

    <xsl:element name="div">
        <xsl:attribute name="class">
            <xsl:text>whatever</xsl:text>
        </xsl:attribute>
    </xsl:element>
  • Fuji Kusaka 2203 posts 4220 karma points
    Feb 22, 2014 @ 04:02
    Fuji Kusaka
    0

    @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. 

     

Please Sign in or register to post replies

Write your reply to:

Draft