RE: [xsl] XHTML and xml:space

Subject: RE: [xsl] XHTML and xml:space
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 31 Jul 2008 16:44:10 +0100
You can ask Saxon to ignore attributes that were supplied as defaults from
the DTD or schema using the option

 -expand:off 

In the case of DTDs it's dependent on the XML parser supplying the necessary
information.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Fredrik Geers [mailto:fredrik@xxxxxxxxxx] 
> Sent: 31 July 2008 15:51
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] XHTML and xml:space
> 
> Hi,
>  
> When transforming xhtml documents, I found out that sometimes 
> an xml:space="preserve" attribute is added.
> If the xhtml document has doctype XHTML Basic 1.0, the 
> attribute is added. If the doctype is XHTML 1.0 Strict, it isn't.
> 
> Why this difference, and how do I prevent it? (without 
> changing the doctype in the original document) I don't want 
> these attributes, because they keep xsl:strip-space from working.
> 
> I'm using Saxon B 9.1.0.1N, with xslt 2.
> 
> Thanks, Fredrik
> 
> 
> Example input:
> <?xml version="1.0" encoding="utf-8"?>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN"
>     "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd";>
> <html xmlns="http://www.w3.org/1999/xhtml";>
> <head><title>Test</title></head>
> <body>
> <div>
>   <span id="test">Test</span>
>   <span id="test2">Test2</span>
> </div>
> </body>
> </html>
> 
> Example XSLT (simple identity transform):
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="2.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:xs="http://www.w3.org/2001/XMLSchema";
> xpath-default-namespace="http://www.w3.org/1999/xhtml";>
> <xsl:output method="xhtml" encoding="UTF-8"/> <xsl:template 
> match="@*|node()">
>   <xsl:copy>
>     <xsl:apply-templates select="@*|node()"/>
>   </xsl:copy>
> </xsl:template>
> </xsl:stylesheet>
> 
> Current result (wanted result is same, but without xml:space
> attributes):
> <?xml version="1.0" encoding="UTF-8"?><html 
> xmlns="http://www.w3.org/1999/xhtml";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> version="-//W3C//DTD XHTML Basic 1.0//EN">
>    <head profile="">
>       <meta http-equiv="Content-Type" content="text/html; 
> charset=UTF-8"
> />
>       <title>Test</title>
>    </head>
>    <body xml:space="preserve">
>       <div xml:space="preserve">
>          <span id="test" xml:space="preserve">Test</span>
>          <span id="test2" xml:space="preserve">Test2</span>
>       </div>
>    </body>
> </html>

Current Thread