[xslt] Structural difference between html and xml output?


given the following xml document:

and a stylesheet:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output indent="no" encoding="ISO-8859-1" method="html"/>
  <xsl:template match="/">
      <body bgcolor="#FFFFFF">
  <xsl:template match="bla">
    <p/> <!-- empty paragraph -->

xsltproc creates 
<html><body bgcolor="#FFFFFF">
for the html output method, and
<?xml version="1.0" encoding="ISO-8859-1"?>
<html><body bgcolor="#FFFFFF"><p/><b>foo</b>blub</body></html>
for xml output.

Now in the html-output the <b>foo</b>blub part is within the <p> element,
as the end element is omitted (b and #PCDATA is allowed content for <p> so
the omitted end tag would be inserted before </body> by a parser). 
In the xml-output the structure is as the stylesheet indicates (closing the 
<p> before <b>).
The same results occur, when I use <p></p> instead of <p/>. It changes
only when the <p> get's content (eg. <p>x</p>).

Now: is this correct?

I admit that this is completely broken html (I didn't write the stylesheets
where I found this problem the first time), but the question remains, if
end tag omission on empty tags should be applied to tag that are not
declared empty in html.
xalan (C++) outputs 
<html><body bgcolor="#FFFFFF"><p></p><b>foo</b>blub</body></html>
on the html method, so it closes the p tag.
A look at the rules for html output in Michael Kays XSLT reference
also indicates, that only some elements should be output without end tag.

xsltproc version is 
xsltproc --version
Using libxml 20409, libxslt 10006 and libexslt 600
xsltproc was compiled against libxml 20409, libxslt 10006 and libexslt 600
libxslt 10006 was compiled against libxml 20409
libexslt 600 was compiled against libxml 20409


Th. Morus WALTER · Manager Content & Data Development
xipolis.net GmbH & Co. KG
Schellingstraße 35 · 80799 München
www.xipolis-base.de · www.mr-check.de · www.xipolis.net

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]