问问题
815 次
2 回答
3
Just have this:
<xsl:template match="p[not(*) and not(normalize-space())]"/>
A complete transformation:
<xsl:stylesheet version="1.0"
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())]"/>
</xsl:stylesheet>
when this transformation is applied on this XML document:
<div>
<p/>
<p> </p>
<p><img src="..."/></p>
<img src="..."/>
</div>
the wanted, correct result is produced:
<div>
<p>
<img src="..."/>
</p>
<img src="..."/>
</div>
于 2012-01-31T13:40:26.337 回答
2
Works for me. I've added an example of using Dimitre's xpath in a drop content rule at https://github.com/plone/diazo/commit/94ddff7117d25d3a8a89457eeb272b5500ec21c5 but it also works as the equivalent xsl:template. The example is pared down to the basics but it works using the complete example content in the question too.
于 2012-01-31T17:31:36.357 回答