<?xml-stylesheet type="text/xml" href="#style1"?>
<!DOCTYPE message [ <!ATTLIST xsl:stylesheet id ID #REQUIRED> ]>
<message>
<xsl:stylesheet id="style1" version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
line 1
<br/>
line 2
</body>
</html>
</xsl:template>
</xsl:stylesheet>
</message>
I validated the XML syntax at https://www.w3schools.com/xml/xml_validator.asp :
In Chrome, the above XML file renders with two <br>
s:
In Firefox, the above XML file renders with one <br>
:
I wonder which is correct? One <br>
or two <br>
?
xsl:output method="xml"
as you use XHTML?<xsl:element name="br"/>
in place of<br/>
? What about other empty HTML elements like<meta>
- do they have the same problem?output method="html"
, if will be the text/html / HTML5 parser, if you useoutput method="xml"
, it will be the XML parser. The HTML5 parser might parse the serialized transformation result into two br elements, it would be worth checking what the HTML5 validators do.<br/>
as XML<br></br>
, if it is then parsed as HTML that indeed creates two HTMLbr
elements martin-honnen.github.io/xslt/2024/test2024071501.html in Chrome.<html><br></br></html>
as two line breaks. But it is invalid HTML according to validator.w3.org/check (it is valid XHTML, however). To avoid the problem, omit thexmlns="http://www.w3.org/1999/xhtml"
from the<html>
element.