[xsl] template match problem

Subject: [xsl] template match problem
From: Chris Bowditch <bowditch_chris@xxxxxxxxxxx>
Date: Sun, 23 Mar 2008 12:17:21 +0000
Hi All,

I have some input XML with the following structure:

<section id="54820" name="INSPECTION TECHNIQUES  KEY POINTS" fragresid="824033925" fragresverid="432002870">
<frag id="4861" name="HE.17133" type="text" fragresid="824033925" fragresverid="432002870">
<lcij>
<p style="Heading_3" xml:space="preserve"/>
<p style="Heading_3" xml:space="preserve"/>
<p style="Heading_3" xml:space="preserve">
<frag id="8" name="TOC Entry Marker" type="text" fragresid="824033895" fragresverid="824033896">
<p xml:space="preserve">
<advanced>
<xsl:variable xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; name="xslVarTocEntry"/>
</advanced>
</p>
</frag>
</p>
<p style="Heading_3" align="center" xml:space="preserve">
<b>INSPECTION TECHNIQUES  KEY POINTS</b>
</p>
<p style="Heading_3" align="center" xml:space="preserve"/>
</lcij>
</frag>
<frag id="2362" name="GT.29704" type="text" fragresid="824033925" fragresverid="432002870">


...

My XSL has 3 template matches:

<xsl:template match="frag" priority="1">
<!-- do default action -->
</xsl:template>
<xsl:template match="frag[@name='TOC']" priority="2">
<!-- do TOC action -->
</xsl:template>
<xsl:template match="frag[(count (descendant::* [name() = 'frag']) = 0) and (count (descendant::* [name()='xsl:variable' and @name='xslVarTocEntry']) > 0)]" priority="2">
<!-- do TOC entry action -->
</xsl:template>


My question is why does the TOC entry template match against the highest level frag element (1st child of section) when it has a child frag element? The condition in the template match should forbid it and cause the default template (with lower priority) to match. What have I missed?

Thanks,

Chris

Current Thread