Copied to clipboard

Flag this post as spam?

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


  • umbracocool 108 posts 197 karma points
    Apr 10, 2012 @ 06:48
    umbracocool
    0

    Problem with spaces between tags in XSLT

     

     

    Hello friends I have a problem with umbraco 4.5 in xslt

    Consequently, when inserted for example that:

    <a href="#" class="sidebar-item"> </ a>

    <div class="clear"> </ div>

    This happens:

    <a href="#" class="sidebar-item">

    <div class="clear"> </ div>

    </ a>

    But doing this <a href="#" class="sidebar-item">&nbsp;</ a>, I work, but not a good practice, and I would not think of this as a solution.

    It is as if the label "<a>" group itself to other labels and this is a big problem. Help me please!

     

     

  • Darren McManaway 4 posts 24 karma points
    Apr 10, 2012 @ 08:12
    Darren McManaway
    0

    To create a space you need to wrap it in xsl:text.

    Like;
    <xsl:text> </xsl:text>

    Otherwise it throws a tassy and mucks all the rendered HTML up afterwards.

    Make sure you wrap everything in if statements as well - just in case the item, doesn't exist.
    Otherwise you'll likely end up with the same problem.

    Cheers!
    :)

  • Chriztian Steinmeier 2726 posts 8320 karma points MVP 4x admin c-trib
    Apr 10, 2012 @ 10:03
    Chriztian Steinmeier
    0

    Hi umbracocool,

    This actually happens because of this setting in the stylesheet (XSLT):

    <xsl:output method="xml" />

    In XML there's no difference between an element with a million spaces and one with none, so the output generated is actually this:

    <a href="#" class="sidebar-item"/>
    <div class="clear"/>

    Which is illegal (X)HTML so the browser compensates by duplicating some elements, which is what you see when using the Firebug (or similar) DOM Inspector.

    You *can* switch the output method to "html", which will generate correct HTML for you, but that can be tricky if you're not very confident in where your generated XML/HTML is used.

    Usually the best option is to use an if statement and check the stuff you're about to output, to make sure that there's actual content - otherwise put an empty comment inside the tag, to make sure it doesn't collapse, e.g.:

    <div class="clear"><xsl:comment /></div>

    /Chriztian

  • umbracocool 108 posts 197 karma points
    Apr 10, 2012 @ 16:21
    umbracocool
    0

    Hey brothers, thanks very much indeed, both methods helped me, God bless you and thanks for your time. A greeting!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies