Re: ambiguous templates

Subject: Re: ambiguous templates
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 7 Nov 2000 18:40:08 +0000

> The below gives me ambiguity error, fine. So how do I implement templates
> that are increasing specialised?

Unfortunately, this is something that you have to do by hand.  You
need to associate a priority with each template using the 'priority'
attribute.  Make your specialised templates have a higher priority
than your general ones, and you'll get the effect you want:

<xsl:template match="st" priority="1">...</xsl:template>
<xsl:template match="sec/st" priority="2">...</xsl:template>
<xsl:template match="bdy/sec/st" priority="3">...</xsl:template>

The only other option is to have a general template that uses
conditional processing to decide what to do. This is an ugly method,
but it has the advantages of not making you keep up with all the
priorities in your stylesheet and keeping the common formatting for
the 'st' elements in the same place.

<xsl:template match="st">
  <xsl:variable name="content">
        <xsl:when test="parent::sec">
          <a name="section{parent::sec/no}">
            <xsl:apply-templates />
        <xsl:otherwise><xsl:apply-templates /></xsl:otherwise>
    <xsl:when test="parent::sec/parent::bdy">
      <font size="+1">
        <xsl:copy-of select="$content" />
    <xsl:otherwise><xsl:copy-of select="$content" /></xsl:otherwise>

I hope that helps,


Jeni Tennison

 XSL-List info and archive:

Current Thread