Copied to clipboard

Flag this post as spam?

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


  • Bogdan Bartis 2 posts 23 karma points
    Dec 06, 2009 @ 18:53
    Bogdan Bartis
    1

    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,

  • Lee 1130 posts 3088 karma points
    Dec 06, 2009 @ 21:12
    Lee
    0

    What happens if you do the following

    <div class="someClass">&nbsp;</div>
  • Lee 1130 posts 3088 karma points
    Dec 06, 2009 @ 21:12
    Lee
    0

    Damn it stripped the text - I wonder if this will work &nbsp;

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 06, 2009 @ 21:22
    Chriztian Steinmeier
    1

    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:

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

    - which will output as:

    <div class="someClass"><!----></div>

    Hope that helps,

    /Chriztian

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 06, 2009 @ 22:31
    Jan Skovgaard
    0

    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

  • J 150 posts 489 karma points
    Dec 07, 2009 @ 00:44
    J
    0

    <div class="someClass">&#160;</div>

  • Jukka-Pekka Keisala 90 posts 226 karma points
    Dec 07, 2009 @ 08:45
    Jukka-Pekka Keisala
    0

    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 &#160;

    Not very beatiful but works.

  • Stephan Lonntorp 195 posts 212 karma points
    Dec 07, 2009 @ 09:55
    Stephan Lonntorp
    0

    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.

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    Dec 07, 2009 @ 10:02
    Lee Kelleher
    2

    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:

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

    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.

  • Bogdan Bartis 2 posts 23 karma points
    Dec 07, 2009 @ 16:51
    Bogdan Bartis
    0

    Hey all,

    First of all thanks for your quick replies. So far I'll go with Chriztian Steinmeier's solutio:

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

    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

Please Sign in or register to post replies

Write your reply to:

Draft