RE: [xsl] nested templates?

Subject: RE: [xsl] nested templates?
From: "Chris Bayes" <Chris@xxxxxxxxxxx>
Date: Wed, 16 May 2001 22:50:29 +0100
Kurt,
>I remember early in the development process that nested templates were a
>part of the test implementations, and in all honesty they didn't really add
>much to the structure and were conceptually a pain to deal with. You can do
>the same thing with a modal call:
>
><xsl:template match="foo">
>    <xsl:apply-templates select="." mode="bar"/>
></xsl:template>
>
><xsl:template match="foo" mode="bar">
>    <!-- do boo.bar -->
></xsl:template>
>

Yeh. I was just thinking that it would avoid some of the mode stuff if you
could do it. In some modal stylesheets it can get quite complicated and
nested templates would avoid that. But like I said I hadn't thought it
through a lot. It just seemed logical to be able to do it. Maye I come from
a too procedural background.

>and you gain the added benefit of still being reference the modal
>"bar" type
>of foo from other templates. <xsl:for-each> can certainly be over-used
>(badly) but again I think that what works best here is to teach people to
>use for-each primarily as a context switcher. It does come into play more
>often with node-sets, however; I have a message board system which orders a
>list of messages in descending order prior to displaying a page of such
>orders:
><xsl:variable name="orderedList">
>    <xsl:for-each select="$messages">
>         <xsl:sort select="date" order="descending"/>
>        <xsl:copy-of select="."/>
>    </xsl:for-each>
></xsl:variable>
>
>Creating an entire template just to copy the contents of a list seemed
>overkill here, so for-each worked fine.

I'm not arguing but wouldn't it be easier to do

    <xsl:apply-templates select="messages">
         <xsl:sort select="date" order="descending"/>
    </xsl:apply-templates>

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


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


Current Thread