xsl-list
[Top] [All Lists]

Re: [xsl] When to use conditional constructions?

2014-03-30 13:59:22
John,

If the conditions can be expressed as mutually exclusive, order doesn't matter.

If this isn't possible, simply use the 'priority' attribute on the
templates that implement what corresponds to the <xsl:when> elements,
so that template for the first <xsl:when> has the highest priority,
..., etc.

The template that corresponds to the <xsl:otherwise> element can
safely be given priority -999999999

 Cheers,
 Dimitre

On Sun, Mar 30, 2014 at 11:49 AM, John Lumley <john(_at_)saxonica(_dot_)com> 
wrote:

On 30 Mar 2014, at 18:28, Michael Kay <mike(_at_)saxonica(_dot_)com> wrote:

I do have a strong preferance for multiple template rules over xsl:choose. I 
think this is mainly because it makes it easier to evolve the code as it 
develops over time. Though a strong downside is that it can be very hard for 
the reader of the code to work out which templates are going to fire under 
which circumstances.

I've found that one of the benefits of using xsl:choose is that it keeps all 
the 'cases' together in one coherent collection. It also has a well-defined 
'priority order'. If you use multiple template rules they can end up 
scattered and difficult to view as a complete set and priority can be 
somewhat awkward.

For example one of my 'pagination' called templates contains an xsl:choose 
with perhaps 15 cases (’page-break?', 'content-fits?', 'can-be-broken?'....) 
that would be much more tricky to prioritise as templates.

Of course use of a unique mode with templates can help, but it would still be 
nice to collect them all together into preferably a single XML node - perhaps 
a package?

John
--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--