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 "/"?
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).
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.
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).
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.
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 "/"?
Regards,
Craig
To get it to output as HTML you can add (or change):
Hi. That's a very well-known issue that has lots of solutions. The one that I prefere is:
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).
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
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
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
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.
Thanks Dan, good suggestion which works nicely.
Regards,
Craig
is working on a reply...