[lxml-dev] Overriding whitespace normalization under XSLT

Lee Brown lee.brown at elecdev.com
Thu Mar 22 15:22:42 CET 2007


Greetings!

There's one problem with using write_c14n(): it strips the DOCTYPE declaration
if present.

I've run into a problem similar to Nathan's when using AJAX to dump preformatted
XHTML into the innerHTML property of a document element.  The preformatted XHTML
must already be in the cannonical form; if not, bad things happen.

In my Apache/ModPython setup, I have an output filter that transforms all
outbound XML into XHTML using XSLT (all with lxml, of course).  So I tried using
write_c14n on the XSLT result tree to solve the above problem, but the missing
DOCTYPE declaration breaks my web pages.

Just for grins and giggles, here's how to force a closing tag on any HTML
element in XSLT:

	<tagname><xsl:text> </xsl:text><tagname>

Using the <xsl:text> element forces non-ignorable whitespace between the
element's opening and closing tags, thus preserving the closing tag in the
output.  Yes, it's rude, crude, and ugly, but it gets the job done without
adding any dependencies to my code.

-----Original Message-----
From: lxml-dev-bounces at codespeak.net [mailto:lxml-dev-bounces at codespeak.net] On
Behalf Of Stefan Behnel
Sent: Wednesday, March 21, 2007 3:14 AM
To: Nathan R. Yergler
Cc: lxml-dev at codespeak.net
Subject: Re: [lxml-dev] Overriding whitespace normalization under XSLT



Nathan R. Yergler schrieb:
> Thanks to everyone for their suggestions.  Sounds like there's not 
> some secret knob to turn (or at least not one that the group knows 
> about).  I did find that passing the result through tidy formats it 
> correctly, so that's the interim fix for me.

The suggestion by Lee Brown could be implemented by canonicalising
(c14n_write) the XML output, in case you want to drop a dependency here.

Stefan





More information about the lxml-dev mailing list