Re: [xsl] template match problem

Subject: Re: [xsl] template match problem
From: Chris Bowditch <bowditch_chris@xxxxxxxxxxx>
Date: Sun, 23 Mar 2008 15:05:43 +0000
Martin Honnen wrote:

<snip/>


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

Thanks for the speedy reply.



<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[@name='TOC']" priority="2">
<template match="frag[@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?

I'm using Xalan 2.7.0. The XML and XSL are part of a larger XML and stylesheet. I'll try to cut it down and see what happens. AFAICT, the parent is a simple <xsl:apply-templates/> call.


In terms of how I check the results. The TOC Entry template has an apply templates call which seems to be processing the p tag siblings above the lowest frag element that the TOC Entry template should only be applied to. (removing this apply-templates call results in none of the p tags appearing in the output) Which tells me that the TOC Entry template must be matching the top level frag element and not the lower level one as expected.



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

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

Thanks for the hint. I already re-wrote part of the expression. I inherited this stylesheet so I'm not sure why name()='xyz' has used in favour of the actual element name everywhere.


Chris

Current Thread