I usually prefer approach 1 because the code is more concise and more
readable / reusable / extensible / customizable.
Performance will depend on the processor. Most processors are likely to
do a linear search of the alternatives in both cases, so it's unlikely
to make much difference (if you're interested in performance, then
measure it!). Some processors may have optimizations for special cases,
but I don't think that should influence your choice unless you need to
squeeze the last ounce of performance: and if you need to do that, the
most effective solution is usually to upgrade your hardware. It's
certainly not a case where what's fastest on one processor will be
fastest on every processor.
Michael Kay
Saxonica
On 03/11/2012 15:24, Norbert Heidbrink wrote:
Hi everybody,
if a node is to be processed differently, depending on a certain
condition, there are two approaches.
Let's say, the condition is "existance of child x".
Approach 1: two templates with different matching XPaths
<template match="thenode[child::x]">
… do_this …
</template>
<template match="thenode[not(child::x)]">
… do_that …
</template>
Approach 2: one template with a conditional instruction
<template match="thenode">
<xsl:choose>
<xsl:when test="x">
… do_this …
</xsl:when>
<xsl:otherwise>
… do_that …
</xsl:otherwise>
</xsl:choose>
</template>
I wonder, if one of these approaches is to be favoured?
Are there any severe implications on performance?
Any other advantages / disadvantages that speak in favour of approach 1
or approach 2?
I am curious to read your estimations,
Norbert
--~------------------------------------------------------------------
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>
--~--