Re: [xsl] use-when

Subject: Re: [xsl] use-when
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Dec 2010 17:42:27 -0500
At 2010-12-17 00:23 +0200, Andriy Gerasika wrote:
but what I need, is to separate static portion of xpath to use-when, both for speed and readability purposes, conditions can be quite complex:
<xsl:template match="some-xpath1" use-when="$first-config-option=('A','B') or $another-config-option='C'">


where config options are set on TransformerFactory level

any ideas?

None that are solved by using the syntax. Variables are not available to you for use-when=. Please see http://www.w3.org/TR/2007/REC-xslt20-20070123/#conditional-inclusion in the table titled "Static Context Components for use-when Expressions".


Another approach is to use your own vocabulary to decorate your XSLT stylesheet constructs and since your stylesheet is an XML document simply run your stylesheet through another preprocessing stylesheet that keeps or strips out various constructs based on your vocabulary and the configuration options:

<xsl:template match="some-xpath1" andriy:include="[1:A,B][2:C]">

... or:

<xsl:template match="some-xpath1" andriy:config1="A B" andriy:config2="C">

... or some expression language you divine to express your concepts of configuration parameters and their values. How you express those concepts could make the original stylesheet very readable. Otherwise I don't see how using use-when= makes a stylesheet more readable than expressing the concept in a predicate.

After having preprocessed your stylesheet based on your configuration parameters, the output stylesheet has only the constructs that are suitable for the configuration, so transform your data with that output stylesheet instead of the original stylesheet. Your preprocessing stylesheet doesn't change so you could pre-compile it when using tools like Saxon to save some time.

What you lose in the preprocessing step you would have to gain back by the speed you claim is lost in the original stylesheet (though I don't understand how much slower it could be for you ... a tool like Saxon works very quickly for template matching ... have you measured any metrics using Saxon options such as "-t"?).

I hope this helps.

. . . . . . . . . . Ken

--
Contact us for world-wide XML consulting & instructor-led training
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread