[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Counting indent level

Subject: Re: Counting indent level
From: Jonas Mellin <jonas.mellin@xxxxxx>
Date: Mon, 29 Sep 2008 09:56:33 +0200
Re:  Counting indent level
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.