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

Subject: Re: [xsl] extracting and removing an element nested at different levels
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Wed, 05 Sep 2012 14:12:16 +0200
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, bpull-styleb programming style. The Right Thingb" 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 wonbt be suppressed because they will be identically reproduced above, they wonbt be processed by apply-templates)
3. otherwise, reproduce document structure identically


Ibd contend that solution 1 isnbt 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 whatbs required here: pull up all Items no matter how deep theybre nested in the List.

Gerrit

Current Thread