|
Subject: Re: comment on 'mode' and also Re: Processing modes From: James Clark <jjc@xxxxxxxxxx> Date: Thu, 15 Apr 1999 18:41:26 +0700 |
Alistair MacDonald wrote:
>
> >>> Lars Marius Garshol <larsga@xxxxxxxxxx> 04/15 8:19 am >>>
> > My understanding of processing modes is that
> > <xsl:apply-templates modes="by-number"/>
> > should only apply template rules that have the by-number mode and
> > ignore all template rules that have no mode.
>
> That should be 'mode', not 'modes'. The match sequence will be a template that
> HAS the required 'mode' and, if that fails a template with NO mode.
If you specify a mode on xsl:apply-template, then template rules in the
stylesheet with no mode are not considered: only the built-in rules are
applied.
> Why ? Because, as I said, modes aren't sticky and have to be
> *EXPLICITLY* passed on. However, <foo> was matched by the IMPLICIT
> rule, which didn't explicitly pass on the mode. This, compined
> with the fact that there is no way of find the *XSL* parameters
> to the triggering <xsl:apply-templates ... /> means that 'mode'
> is *almost* useless. (It *DOES* have uses, but trying to use it
> effectively means implementing lots of "do-nothing" templates
> which just call apply-templates with the same mode as they had!)
Why do you need lots of "do-nothing" template rules. You need one
"do-nothing" template rule:
<xsl:template match="*" mode="by-number">
<xsl:apply-templates mode="by-number"/>
</xsl:template>
> There is no reason why 'mode' should not be sticky, since it
> could easily be cancelled ('mode=""') and, if no mode is matched
> it defaults to the empty mode.
There are two separate issues:
(a) whether modes should be sticky
(b) whether the built-in rule remains in the same mode or switches back
to the initial mode
The sticky versus non-sticky modes issue is very similar to the dynamic
versus lexical scoping issue. Sticky modes like dynamic scoping is
seductive but a bad idea. With non-sticky modes you can tell just by
looking at the stylesheet which templates are applicable for a given use
of xsl:apply-templates.
On the built-in rule issue, I think there are arguments both ways.
Whichever way you do it, you can get the other behaviour by adding a
single additional template rule for each mode.
James
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| comment on 'mode' and also Re: Proc, Alistair MacDonald | Thread | Re: comment on 'mode' and also Re: , Lars Marius Garshol |
| Re: comment on 'mode' and also Re: , Lars Marius Garshol | Date | Re: Python & XML, Matthew MacKenzie |
| Month |