xslt-1.0

How to force XSLT doesn't close tags like <source/>


So I'm using XSLT to make HTML out of XML, and in my code I have something like this: <input/> but XSLT convert it to HTML like <input></input>, so W3 validator shows me errors like "Stray end tag input".

I've tried to do <xsl:output method="xhtml" indent="yes" />, but after that my page is doing parkour, and doesn't seem correct at all, but at least those inputs is fine, and not closed, as I want it to be.

So I wan't to keep those inputs fine, and not closed, but prevent my page from doing parkour. As I understand, <xsl:output method="xhtml" indent="yes" /> - makes all tags don't close themself. I want to apply this only for certain specific tags, like <input/> or <img/>

UPDATED: I just fix my problem with inputs. In some of my xslt templates, I had <xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">. So when I notice, that some of my inputs is doing well, and some of them had closed tag, I did remove xmlns="http://www.w3.org/1999/xhtml" part, so my inputs become fine, with just <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">.

But I still have the same problem with <source> tag. My code example is:

<picture>
  <source media="(min-width:768px)" srcset="{$template-resources}images/banner.png"/>
  <source media="(min-width:420px)" srcset="{$template-resources}images/banner768.png"/>
  <img src="{$template-resources}images/banner420.png" style="width:auto;" alt="Скидка 20% на книги в печати" itemprop="contentUrl"/>
</picture>

So, my <img> tag seems fine, and don't have closing tag, like I want it. But <source> tags still have closing tags in html output, which gives me w3 validator errors, like: "Stray end tag source".


Solution

  • I still have the same problem with <source> tag

    The XSLT 1.0 specification states:

    The html output method should not output an end-tag for empty elements. For HTML 4.0, the empty elements are area, base, basefont, br, col, frame, hr, img, input, isindex, link, meta and param.

    Apparently the source element was added later - so if you want to see it included, you will need to upgrade to a more recent processor or try to hack your stylesheet to produce something it does not considers to be a valid output (not recommended, but with some effort should be possible).