Copied to clipboard

Flag this post as spam?

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


  • Craig100 1136 posts 2523 karma points c-trib
    Oct 14, 2011 @ 14:10
    Craig100
    0

    XSLT output valid HTML5 failing

    Hi,

    I have the following XSLT script used for recursively getting a header logo for an HTML5 <section> element as a background image. However I can't get it to save and work unless I have an unwanted "/" at the end of the section tag. Is there a way of getting this to work AND validate as HTML i.e. lose the "/"?

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets PS.XSLTsearch ">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="currentPage"/>
      <xsl:template match="/">
      <xsl:variable name="imageId" select="$currentPage/ancestor-or-self::*[normalize-space(headerImage)][1]/headerImage" />
      <xsl:variable name="mediaXml" select="umbraco.library:GetMedia($imageId, 0)"/>
      <xsl:variable name="umbracoFile" select="$mediaXml/umbracoFile"/>
      <section id="logo_section" style="background:url('{$umbracoFile}');" />
    </xsl:template>
    </xsl:stylesheet>

    Regards,

    Craig

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 14, 2011 @ 14:14
    Dan Diplo
    1

    To get it to output as HTML you can add (or change):

    <xsl:output method="html" omit-xml-declaration="yes"/>
  • Rodion Novoselov 694 posts 859 karma points
    Oct 14, 2011 @ 14:20
    Rodion Novoselov
    1

    Hi. That's a very well-known issue that has lots of solutions. The one that I prefere is:

    <section>
    <xsl:comment />
    </section> 
  • Rodion Novoselov 694 posts 859 karma points
    Oct 14, 2011 @ 14:32
    Rodion Novoselov
    0

    Dan, I suspect that changing the output method is little of help, since the xslt itself still should be valid xml. I suppose that the problem was not a desire to generate invalid xhtml (which nevertheless still can be valid html5 since the latter doesn't strictly require open-closing tag matching) but just to prevent auto-closing an empty section tag (what xslt does by default).

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Oct 14, 2011 @ 14:36
    Tom Fulton
    0

    Are you wanting to output a closing section tag, ie <section  id="logo_section" style="background:url('{$umbracoFile}');"></section>?  If so the output method adjustment that Dan suggested should create those results.

    If not, what is the markup you want to generate?

    -Tom

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Oct 14, 2011 @ 14:53
    Chriztian Steinmeier
    0

    I assume you're using the HTML5 doctype in the Master template, so I would definitely go with setting the output method to html, which will work just fine, but you still need to keep the XSLT file valid (by closing the section element). The output method just determines how the processed output tree should be serialized.

    If the output of the stylesheet is to be used in another macro, or you're using this as an include file, you shouldn't use the html method (it won't be valid XML and thus can't be processed with XSLT).

    /Chriztian

     

  • Craig100 1136 posts 2523 karma points c-trib
    Oct 14, 2011 @ 15:37
    Craig100
    0

    Thanks for all the comments. This is my very first Umbraco site so I'm still feeling my way around.

    It currently outputs this to the page: <section id="logo_section" style="background:url('/media/187/origins-test.jpg');" />

    I want it to output this: <section id="logo_section" style="background:url('/media/187/origins-test.jpg');">

    The total <section> in HTML is contained within a <header> section and is this:-

                <section id="logo_section" style="background:url('/media/187/origins-test.jpg');">

                    <a href="" title="home"><span id="logo_text">TEST</span>

                    <span id="logo_subtext">Family History</span></a>

                </section>

    I'm hoping I don't have to make compromises in the output due to CMS restrictions;) Would it be any better done in Razor?

    Craig

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 14, 2011 @ 15:54
    Dan Diplo
    0

    If you use Razor, your output won't be changed, as Razor doesn't care if your output is valid XML.

    If you want to use XSLT then I'd consider outputting the entire <section>....</section>  block in your XSLT so it knows there is a closing tag and so won't try and self-close it for you.

  • Craig100 1136 posts 2523 karma points c-trib
    Oct 14, 2011 @ 16:04
    Craig100
    0

    Thanks Dan, good suggestion which works nicely.

    Regards,

    Craig

Please Sign in or register to post replies

Write your reply to:

Draft