RE: [xsl] Problem with xsl:template using XSLT 1.0

Subject: RE: [xsl] Problem with xsl:template using XSLT 1.0
From: "Scott Trenda" <Scott.Trenda@xxxxxxxx>
Date: Wed, 5 Dec 2007 10:49:30 -0600
This received a lot more replies than I had initially expected. :/

I gave that advice to start with because I thought it would ensure that
he'd avoid context-dependent expressions in his match patterns. From
what I've been reading in the replies, there seems to be a lot of
personal coding style decisions that can lead to several different but
functionally equivalent stylesheets in the end. Myself, I like to have
more control over my output document, and so I only let the default
behavior take over when I know it'll do exactly what I want. Generally
it's as simple as starting with a root-match template and applying
templates selectively.

Could this thread die now? Seems we're kind of chasing our tails here.

~ Scott


-----Original Message-----
From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
Sent: Wednesday, December 05, 2007 10:43 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] Problem with xsl:template using XSLT 1.0

>     Remember that your <xsl:template/> elements should match
>     fairly generically (match="player" in this case), and
>     your <xsl:apply-templates/> elements should be where you
>     narrow down your selection.
>
>   I just say that in general, I would give instead the
> opposite advice.  Of course, there is place for both
> patterns, and I expect any not-simple-toy-stylesheet to use
> both.  With experience, when using one or the other become
> quite obvious.

To me the telltale sign that you've got it wrong is when the body of the
xsl:template rule consists of an xsl:choose instruction.

There are many cases where it really doesn't matter too much. For
example,
"process all attributes except width and height" (which came up this
morning) can equally well be written as

<xsl:apply-templates select="@* except (@width, @height)"/>

or as <xsl:apply-templates select="@*"/> with

<xsl:template match="@width|@height"/>

There really isn't all that much to choose between them. However, if
you're
only processing a very small proportion of the nodes, then selecting the
nodes to be processed in the select attribute of xsl:apply-templates
will
probably be more efficient.

Michael Kay
http://www.saxonica.com/

Current Thread