xsl-list
[Top] [All Lists]

Re: [xsl] template match problem

2008-03-23 05:58:32
Chris Bowditch wrote:

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?

I am not able to reproduce the problem, I took your XML snippet and added a closing </section>, then I made this stylesheet with your three templates given a body indicating what happens

<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
  version="1.0">

  <xsl:template match="section">
    <root>
      <xsl:apply-templates/>
    </root>
  </xsl:template>

<xsl:template match="frag" priority="1">
  <template match="frag" priority="1"/>

</xsl:template>
<xsl:template match="frag[(_at_)name='TOC']" priority="2">
  <template match="frag[(_at_)name='TOC']" priority="2"/>
</xsl:template>
<xsl:template match="frag[(count (descendant::* [name() = 'frag']) = 0) and (count (descendant::* [name()='xsl:variable' and @name='xslVarTocEntry']) > 0)]" priority="2">
  <template match="frag[count ..." priority="2"/>
</xsl:template>
</xsl:stylesheet>

and run it with Saxon 6.5, the result is

<?xml version="1.0" encoding="utf-8"?><root>
                <template match="frag" priority="1"/>
                <template match="frag" priority="1"/>
              </root>

Can you post a minimal but complete XML input and stylesheet and tell us which XSLT processor you use and how you check which template is choosen?


Also note that the conditions in the third template could be rewritten as

<xsl:template
  match="frag[not(descendant::frag) and
              descendant::xsl:variable[(_at_)name='xslVarTocEntry']]"


--

        Martin Honnen
        http://JavaScript.FAQTs.com/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>