I have a Plone website thematic with plone.app.theming. The problem is that the design is pretty strict and does not involve any empty <p>
elements or any other meaningless TinyMCE outputs. Such elements violate the intended design. Therefore, I want to remove empty elements from the content. I tried inline xslt (which according to http://diazo.org/advanced.html#inline-xsl-directives should be supported):
<xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="*[not(*) and not(text()[normalize-space()])]"/>
But it did not help. In fact, it did something strange. The empty p
tags that I wanted to get rid of remained unchanged, but some other elements like
<a href="mylink"> <img src="../++theme++jarn.com/whatever.png" /></a>
turned into
<a href="mylink"></a>
with a crossed out image. Replacing match="*[…
in the second template with match="p[…
did not crop the images, but these nasty <p>
were still in the output.
Any tips on how to get rid of empty elements using Diazo rules?
UPDATE January 31, 2012 Here is the content from which I need to remove p
tags:
<div id="parent-fieldname-text"> <p></p> <p> </p> <p> </p> <p><section id="what-we-do"> <p class="visualClear summary">Not empty Paragraph</p> <ul class="thumbsList"> <li><a href="mylink"> <img src="../++theme++jarn.com/whatever.png" /></a></li> <li><a href="mylink"> <img src="../++theme++jarn.com/whatever.png" /></a></li> </ul> </section></p> </div>
Diazo conversion rules:
<?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"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:strip-space elements="*"/> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="p[not(*) and not(normalize-space())]"/> <theme href="index.html" css:if-content="#visual-portal-wrapper" /> <replace css:theme-children="div.contentWrapper" css:content-children="#content" /> </rules>
The result that I get after applying the transformations to the Plone website is completely identical to the input, while I expect to get these three empty <p>
tags after opening the <div>
to leave.
If I changed the second template to fit all elements, such as match="*…
, then the images will be deleted, but empty <p>
tags still exist.