Re: [xsl] Counting indent level

Subject: Re: [xsl] Counting indent level
From: Jonas Mellin <jonas.mellin@xxxxxx>
Date: Mon, 29 Sep 2008 09:56:33 +0200
Nicholas Orr wrote, On 2008-09-29 04:51:
On 29/09/2008, at 11:38 AM, G. Ken Holman wrote:

I've got some XML that contains a list of items and groups, and each
group could contain either more items or more groups like so :

<catalog>
       <item />
       <group>
               < group >
               < item />
               < item />
               < group >
                       < group >
                               < item />
etc

So groups can contain either items or more groups or nothing.  Items
only exist at the root (catalog) of this part of the tree or inside
groups.  I'm outputting a single list of all of the items and group
currently using this :

<xsl:for-each select="item|descendant::group|descendant::group/item">

I expect you would have a more easily maintained stylesheet if you had:

This entire xslt file is pretty simple, it's basically just that one for each and produces a single list of elements. Is there any other advantages (other than easier maintenance) to use templates over the for-each?
One advantage is that using the default processing engine in XSLT where rules are expressed in terms of templates are more robust, if the templates are properly defined, than for-each in terms of handling faulty but well-formed XML formatted data. In particular, omission of expected nodes (elements, attributes, etc.) can be handled. Note that by validating the XML formatted data, you can avoid such situations.

[...]

/Jonas

--
Carpe Diem!
===
Jonas Mellin, Assistant Professor in Computer Science
School of Humanities and Informatics, Building E-2
University of Skvvde, P.O. Box 408, SE-541 28 Skvvde, Sweden
Phone: +46 500 448321, Fax: +46 500 448399
Email: jonas.mellin@xxxxxx, URL: http://www.his.se/melj

Current Thread