Re: [xsl] Output in XML / HTML, double tags and CDATA in script.

Subject: Re: [xsl] Output in XML / HTML, double tags and CDATA in script.
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 17 Feb 2009 18:40:08 +0100
G. Ken Holman wrote:
At 2009-02-17 20:20 +0300, P!P>P;P>P2Q P5P2 PP=P4QP5P9 wrote:
Hi. I have such XSLT code:
...
   <br/>
   <img src="test.jpg"/>
...

When i'm using output method="html", i have <br/> and <img/> tags transformed to <br></br> and <img></img>.

This is not conformant behaviour:


  http://www.w3.org/TR/xslt#section-HTML-Output-Method
  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. For example, an element written as
  <br/> or <br></br> in the stylesheet should be output as
  <br>.

The html output method applies to HTML elements in no namespace while the posted stylesheet had


<xsl:stylesheet
version="1.0"
xmlns="http://www.w3.org/1999/xhtml";
xmlns:php="http://php.net/xsl";
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

so it creates its result elements in the XHTML namespace http://www.w3.org/1999/xhtml and for those the html output method does not apply so the processor is free to serialize as e.g. <br></br>.


To the original poster: I don't think there is a good solution as long as you are trying to create XHTML (to be served as text/html) with an XSLT 1.0 processor. XSLT 2.0 has an output method 'xhtml' which should do what you want but XSLT 1.0 processors like libxslt do not support that I think. You can make your life a lot easier by changing your XSLT stylesheet to create HTML 4 documents instead as then the html output method applies.

--

	Martin Honnen
	http://JavaScript.FAQTs.com/

Current Thread