How can I preserve white spaces between tags with Diazo?

449 views Asked by At

I'm creating a simple Diazo theme.

The rules.xml is something like this:

<?xml version="1.0" encoding="UTF-8"?>
<rules
    xmlns="http://namespaces.plone.org/diazo"
    xmlns:css="http://namespaces.plone.org/diazo/css"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <theme href="index.html"/>

    <replace css:content="#form-1" css:theme="#form-1" />

</rules>

And in a content file, there's the following lines:

...
<div id="form-1">
    <form action="...">
        <input type="text" id="name" />
        <input type="submit" value="ok" />
    </form>
</div>
....

I expected that these lines were replicated exactly in the same way in the output html. However, they became like this:

<div id="form-1">
    <form action="...">
        <input type="text" id="name" /><input type="submit" value="ok" /></form>
</div>

That is, every time I have an empty html tag, like <input ... /> or <br />, the white space between it and the next tag is removed.

I've tried to modify this behaviour using <xsl:output> and <xsl:preserve-space> options, without success.

What can I do?

2

There are 2 answers

0
scarba05 On

I'm facing this same issue. This is a bug.

Diazo uses lxml, a Python XML library. lxml uses 2 C libraries, libxml2 and libxslt. This is most likely a bug in one of these 2 libraries.

Quite possibly it is this bug:

https://bugzilla.gnome.org/show_bug.cgi?id=642191

The most obvious solution is to add some margin to the inputs in your CSS.

0
scarba05 On

An alternative solution to editing your css would be to re-introduce the spaces in your rules file.

<replace css:content="#form-1 input">
    <xsl:copy-of select="." /><xsl:value-of select="'&#32;'"/>
</replace>

This is a bit of a hack but works for me.