xsl-list
[Top] [All Lists]

Re: [xsl] extracting and removing an element nested at different levels

2012-09-05 07:12:56


On 2012-09-05 06:52, Mark wrote:
Hi Gerrit,
Thanks for your suggestion. Both worked perfectly for me and produced
identical results. Is there any advantage in using one technique rather
than the other?
Mark

Mark,

In this case, no.

xsl:for-each is often regarded as an indication of an imperative, “pull-style” programming style. The Right Thing™ to do is to define templates, use xsl:apply-templates and let the input drive your transformation. So this general consideration will favor the first solution over the second.

To recap, the 1st solution was:
1. match List in default mode, select all descending Items and apply-templates to them in default mode 2. match Item in default mode, reproduce just this element but process contents in "suppress-item" mode
3. match Item in "suppress-item" mode, suppress it
4. otherwise, reproduce document structure identically

2nd solution:
1. match List in default mode, select all descending Items, iterate over them, reproduce them in place, process their contents 2. match Item in default mode, suppress it (the outermost items won’t be suppressed because they will be identically reproduced above, they won’t be processed by apply-templates)
3. otherwise, reproduce document structure identically

I’d contend that solution 1 isn’t really a pure-play push solution but a pull solution in disguise because you select (pull) the Items explicitly. It just avoids the explicit use of xsl:for-each that XSLT hardliners (like myself) might frown upon.

But after all, that what’s required here: pull up all Items no matter how deep they’re nested in the List.

Gerrit

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--