RE: [xsl] Using keys in templates

Subject: RE: [xsl] Using keys in templates
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 13 Jul 2004 13:16:07 -0400
At 12:06 PM 7/13/2004, it was written:
When you specify which nodes are selected in your apply-templates call
then there isn't ever any doubt which nodes are being processed or not.
It's almost always better to specify exactly which nodes you want to
process in an <xsl:apply-templates select=""/> then to either use ifs
inside a template or a match on a template.

My personal $0.02 is that while this contains an element of truth, it is overstated. The price in performance that you pay for using template matches to sort things out is actually going to be a problem in only a tiny fraction of cases (depending on your problems, dataset, and system specs of course).


That is, I see only the most theoretical and potential of problems with

<xsl:template match="one">Do something</xsl:template>

<xsl:template match="two"><!-- do nothing --></xsl:template>

... and moreover, I think it's generally a mistake to distort your code, or not use techniques that are otherwise perfectly good, to avoid a problem you probably won't ever have. None of these rules are hard and fast; but typically I'll watch out for only the most egregious problems (using '//' from the root many times, for example, in a document not trivially small), unless I actually have a performance problem I have to address. (The post here doesn't actually say why it's supposed to be bad, but theoretical performance comparisons are the only argument I've seen.)

Using template matches to filter nodes is not, IMHO, so egregious -- sometimes it even has a Taoist, XSLTish elegance to it -- and Nicolas evidently has a good reason to do it (and seemingly no performance problem on the horizon), so why not?

Cheers,
Wendell

-----Original Message-----
From: Nicolas Mailhot [mailto:Nicolas.Mailhot@xxxxxxxxxxx]

Well, you're right but with priorities you can poison the default
template with an xml:message and detect when a node that isn't supposed
to be processed is.

Anyway, thanks for the advice !

--
Nicolas Mailhot


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread