xslt, output closed tags

J

Jesper Moth

The MSXML4 xslt-parser would output any source <div/> like this:

<div></div>

I never figured out how to disable this behaviour. But since it makes the
source document look cleaner, and since most browsers require empty divs to
be markup up this way, I didn't really give it an extra thought untill I
moved to the Tomcat 4.1 where the *reverse* situation applies. The native
xslt-parser outputs any <div></div> like this:

<div/>

- effectively misrendering the page in certain important browsers. And it's
not just the content of the source document that outputs like this; it's
also the content of the templates themselves:

<xsl:template match="/">
<div>
<h1>Hello</h1>
<div></div> <!-- this becomes <div/> in output -->
<div>
<xsl:template>

My first thought was to change the output method to HTML, but amazingly
this didn't change anything; and I would also like to avoid this. I have no
idea on how to go about this and I can't figure out how the spec is
supposed to be read on this subject. What I would like is to have my
source-file <input/> elements and my <div></div> elements rendered exactly
like that [transforming xhtml2 to xhtml1]. Here is my output tag:

<xsl:eek:utput
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
method="xml"
encoding="UTF-8"
omit-xml-declaration="no"
indent="yes" />
 
M

Martin Honnen

Jesper said:
The MSXML4 xslt-parser would output any source <div/> like this:

<div></div>

I never figured out how to disable this behaviour. But since it makes the
source document look cleaner, and since most browsers require empty divs to
be markup up this way, I didn't really give it an extra thought untill I
moved to the Tomcat 4.1 where the *reverse* situation applies. The native
xslt-parser outputs any <div></div> like this:

<div/>

- effectively misrendering the page in certain important browsers. And it's
not just the content of the source document that outputs like this; it's
also the content of the templates themselves:

<xsl:template match="/">
<div>
<h1>Hello</h1>
<div></div> <!-- this becomes <div/> in output -->
<div>
<xsl:template>

My first thought was to change the output method to HTML, but amazingly
this didn't change anything; and I would also like to avoid this. I have no
idea on how to go about this and I can't figure out how the spec is
supposed to be read on this subject. What I would like is to have my
source-file <input/> elements and my <div></div> elements rendered exactly
like that [transforming xhtml2 to xhtml1]. Here is my output tag:

<xsl:eek:utput
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
method="xml"
encoding="UTF-8"
omit-xml-declaration="no"
indent="yes" />

Consider to use
<xsl:eek:utput method="html"
that way you should have no problems with HTML browsers.
Only XSLT 2 has
<xsl:eek:utput method="xhtml"
to produce XHTML that is backwards compatible to HTML browsers.
 
J

Jesper Moth

Martin Honnen wrote
Consider to use
<xsl:eek:utput method="html"
that way you should have no problems with HTML browsers.
Only XSLT 2 has
<xsl:eek:utput method="xhtml"
to produce XHTML that is backwards compatible to HTML browsers.

Thanks Martin. Weird thing is that a "html" output does not prevent empty
elements from being closed xml-style in the Tomcat native parser. It will
also not impress the ladies.

I wrote some templates to fix the problem for now [adding whitespace
content to script, textarea and iframe elements]. If I can figure out how
to upgrade these Xerces and Xalan compontents I can always hope that they
behave differently in this respect; after all, the MSXML parser got it
right without any extra effort [usually this implies that it got it wrong
according to specs, but I can't say for sure in this case]. Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top