Re: [xslt] LibXSLT adding annoying whitespace



Le 13/06/01 01:49:21, Michael Nachbaur a écrit :
> Here is an example that will illustrate my problem: [...]
> Example 2 (XSL):
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="html"/>
> 
>   <xsl:template match="/">
>     <html><body><img/><br/><a><img/></a></body></html>
>   </xsl:template>
> </xsl:stylesheet>
> 
> Example 2 (Output):
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
> "http://www.w3.org/TR/REC-html40/loose.dtd">
> <html><body>
> <img>
> <br>
> <a><img></a>
> </body></html>

In the XSLT spec, 16.2 HTML Output Method:
  «If the index attribute has the value yes, then the html output method
may add or remove whitespace as it outputs the result tree, so long as it
does not change how an HTML user agent would render the output. The default
value is yes.»

And in the HTML spec, B.3.1 Line Breaks
<http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.1> :
  «SGML (see [ISO8879], section 7.6.1) specifies that a line break
immediately following a start tag must be ignored, as must a line break
immediately before an end tag. This applies to all HTML elements without
exception.»

This means:
<html><body><img/><br/><a><img/></a></body></html>
is strictly equivalent to
<html><body>
<img>
<br>
<a><img></a>
</body></html>
for any conforming user agent, so it isn't a bug of libxslt/libxml.

However, try using indent="no" in your xsl:output element (not tested...)

Tom.




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