Output method html not closing empty tags

View: New views
3 Messages — Rating Filter:   Alert me  

Output method html not closing empty tags

by Brecht Yperman-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

We have an externally generated XSLT which we use for a transformation using Xalan.

The result however is not as expected.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="fn link xbrldi xbrli xdt xlink xs xsi">
                <xsl:output version="4.0" method="html" indent="no" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
                <xsl:param name="SV_OutputFormat" select="'HTML'"/>
                <xsl:variable name="XML" select="/"/>
                <xsl:template match="/">
                               <html>
                                               <body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in">
                                                               <img>
                                                                              <xsl:attribute name="src">
                                                                                              <xsl:text>file:///</xsl:text>
                                                                              </xsl:attribute>
                                                               </img>
                                               </body>
                               </html>
                </xsl:template>
</xsl:stylesheet>

This results in the following output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:altova="http://www.altova.com"><body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in"><img src="file:///"></body></html>

As you can see the <img/> tag is not well formed, and we'd like to have XHTML.

The result is OK when we use <xsl:output method="xml" />, but we don't have control over the stylesheet.

I drilled it down to line 1011 of ./trunk/src/org/apache/xml/serializer/ToHTMLStream.java

What's the reason for this not to be:
writer.write('/>');
?
Thanks,
Brecht

Re: Output method html not closing empty tags

by keshlam :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I believe this is correct HTML output. HTML tags can often be implicitly closed, since HTML is based on SGML.

If you want things explicitly closed, you want XML or XHTML output. Unfortunately, XHTML support isn't available in Xalan at this time; it's only a standard feature in XSLT 2.0, and Xalan is a 1.0 processor. So the best advice I can give you is to select XML if you want the document to look more like XHTML (and be well-formed XML), or HTML if you want the document to be HTML (which is not required to be well-formed XML).

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
 -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish (
http://www.ovff.org/pegasus/songs/threes-rev-11.html)


Brecht Yperman <Brecht.Yperman@...>

10/08/2009 11:22 AM

To
Brecht Yperman <Brecht.Yperman@...>, "xalan-j-users@..." <xalan-j-users@...>
cc
Subject
Output method html not closing empty tags





Hi,

We have an externally generated XSLT which we use for a transformation using Xalan.

The result however is not as expected.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="fn link xbrldi xbrli xdt xlink xs xsi">
                <xsl:output version="4.0" method="html" indent="no" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="
http://www.w3.org/TR/html4/loose.dtd"/>
                <xsl:param name="SV_OutputFormat" select="'HTML'"/>
                <xsl:variable name="XML" select="/"/>
                <xsl:template match="/">
                               <html>
                                               <body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in">
                                                               <img>
                                                                              <xsl:attribute name="src">
                                                                                              <xsl:text>
file:///</xsl:text>
                                                                              </xsl:attribute>
                                                               </img>
                                               </body>
                               </html>
                </xsl:template>
</xsl:stylesheet>

This results in the following output:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html xmlns:altova="
http://www.altova.com"><body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in"><img src="file:///"></body></html>

As you can see the <img/> tag is not well formed, and we'd like to have XHTML.

The result is OK when we use <xsl:output method="xml" />, but we don't have control over the stylesheet.

I drilled it down to line 1011 of ./trunk/src/org/apache/xml/serializer/ToHTMLStream.java

What's the reason for this not to be:
writer.write('/>');
?
Thanks,
Brecht


Re: Output method html not closing empty tags

by Christoffer Dam Bruun :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have experienced something similar.

I had
<tag>
   <xsl:choose>
   .....
   </xsl:choose>
</tag>

In the situations where no output was generated between <tag> and </tag>
then Xalan would suppress writing </tag> to the result tree.

I fixed those specific situations by adding:
<xsl:text> </xsl:text>
before just before </tag>

Best regards
Christoffer Bruun

Brecht Yperman wrote:

> Hi,
>
> We have an externally generated XSLT which we use for a transformation using Xalan.
>
> The result however is not as expected.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:link="http://www.xbrl.org/2003/linkbase" xmlns:xbrldi="http://xbrl.org/2006/xbrldi" xmlns:xbrli="http://www.xbrl.org/2003/instance" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" exclude-result-prefixes="fn link xbrldi xbrli xdt xlink xs xsi">
>                 <xsl:output version="4.0" method="html" indent="no" encoding="UTF-8" doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" doctype-system="http://www.w3.org/TR/html4/loose.dtd"/>
>                 <xsl:param name="SV_OutputFormat" select="'HTML'"/>
>                 <xsl:variable name="XML" select="/"/>
>                 <xsl:template match="/">
>                                <html>
>                                                <body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in">
>                                                                <img>
>                                                                               <xsl:attribute name="src">
>                                                                                               <xsl:text>file:///</xsl:text>
>                                                                               </xsl:attribute>
>                                                                </img>
>                                                </body>
>                                </html>
>                 </xsl:template>
> </xsl:stylesheet>
>
> This results in the following output:
> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
> <html xmlns:altova="http://www.altova.com"><body style="margin-left=0.6in; margin-right=0.6in; margin-top=0.79in; margin-bottom=0.79in"><img src="file:///"></body></html>
>
> As you can see the <img/> tag is not well formed, and we'd like to have XHTML.
>
> The result is OK when we use <xsl:output method="xml" />, but we don't have control over the stylesheet.
>
> I drilled it down to line 1011 of ./trunk/src/org/apache/xml/serializer/ToHTMLStream.java
>
> What's the reason for this not to be:
> writer.write('/>');
> ?
> Thanks,
> Brecht
>