RE: [xsl] using few or many templates?

Subject: RE: [xsl] using few or many templates?
From: "Evan Lenz" <elenz@xxxxxxxxxxx>
Date: Fri, 16 Mar 2001 23:56:52 -0800
I agree with Larry that the modularity of template rules can facilitate
easier maintenance. I wouldn't necessarily agree that such stylesheets are
generally easier to read. Since the pull-based approach of xsl:for-each
enforces a particular order on the result tree, it reduces the number of
possible results; without knowing anything about the source tree, it is much
easier to see what's going on in a pull-based stylesheet as opposed to a
stylesheet using many template rules. This, of course, is largely wherein
the power of template rules lies.

That said, I err on the side of using template rules more often than not.
Dan's example, IMHO, lends itself to using template rules, in the same way
as he demonstrates, except without the redundancy. All you need are these
four rules (and perhaps <xsl:strip-space/> if you care about extra
whitespace in the output), rather than Dan's seven:

  <xsl:template match="A">
    <table>
      <xsl:apply-templates/>
    </table>
  </xsl:template>

  <xsl:template match="B | C">
    <tr><td><xsl:value-of select="."/></td></tr>
  </xsl:template>

  <xsl:template match="E">
    <tr><td></td><td><xsl:value-of select="."/></td></tr>
  </xsl:template>

  <xsl:template match="G">
    <tr><td></td><td></td><td><xsl:value-of select="."/></td></tr>
  </xsl:template>


Anyway, this balance has been discussed here before. Here's a link to one of
the more recent threads:
http://www.biglist.com/lists/xsl-list/archives/200102/threads.html#01737

Evan Lenz
XYZFind Corp.


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread