0

This is somewhat related to XSLT wont allow me to use self-closing img and br tags but I don't think it's a duplicate.

I want to transform XML to HTML. In the source XML, there are self-closing <lb/> elements. I want to transform these into valid HTML <br> void elements.

To get valid HTML, I set the output method to HTML:

<xsl:output method="html" encoding="UTF-8" indent="no"/>

The XSLT code looks like this:

<xsl:template match="//lb">
    <br/>
</xsl:template>

But as output, I get this

<br></br>

which is interpreted by an HTML5 parser as

<br><br>

How to get one valid HTML void element?

Sebastian
  • 1,710
  • 2
  • 16
  • 28
  • Which XSLT processor? – michael.hor257k May 24 '17 at 14:19
  • Saxon-HE 9.7.0.15 – Sebastian May 24 '17 at 14:20
  • 2
    There is something you're not telling us. The problem cannot be reproduced using the posted code alone: http://xsltransform.net/93dEHFH – michael.hor257k May 24 '17 at 14:21
  • 1
    The `html` output method is applied to known HTML elements in no namespace so I suppose your `br` element is in a certain namespace and therefore the serializer does not serialize as you want. So either make sure your result elements are in no namespace or if you have them in the XHTML namespace use method `xhtml`. – Martin Honnen May 24 '17 at 14:32
  • Thank you both! Yes, you are right, this was a namespace issue. A misplaced `xmlns` attribute was in the `` element. – Sebastian May 24 '17 at 14:44

0 Answers0