Based on your clarifications, this is how you can select p
elements only if they contain exactly one span
element.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="root">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="p[count(span)=1]">
<xsl:copy>
<xsl:copy-of select="*|text()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*"/>
</xsl:stylesheet>
Input XML I used:
<?xml version="1.0" encoding="utf-8"?>
<root>
<p>
<span>wrong</span>
<span>wrong</span>
<span>wrong</span>
</p>
<p>
<span>right</span>
</p>
<p>
<span>wrong</span>
<span>wrong</span>
<span>wrong</span>
</p>
<p>
<span>right</span>
</p>
</root>
Output XML:
<?xml version="1.0" encoding="UTF-8"?>
<p>
<span>right</span>
</p>
<p>
<span>right</span>
</p>