[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: mode computation case

Subject: Re: mode computation case
From: ac <ac@xxxxxxxxxxxxx>
Date: Thu, 02 Sep 2010 22:16:11 -0400
Re:  mode computation case
Hi Michael, Wendell, David,

As a note, by separating preparation and dispatch, and assuming that all parameters for all modes are tunneled and common, the following:

<xsl:template name="prepare-and-dispatch">
...
<xsl: variable name="var1" select="...some value or node-set generating expression"/>
<xsl: variable name="var1" select="...some other value or node-set generating expression"/>
<xsl: variable name="var1" select="...some other other value or node-set generating expression"/>
<xsl: variable name="var1" select="...another value or node-set generating expression"/>
<xsl:choose>
<xsl:when test="@mode eq 'mode1'">
<xsl:apply-templates select="$nodetree" mode="mode1">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@mode eq 'mode2'">
<xsl:apply-templates select="$nodetree" mode="mode2">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@mode eq 'mode3'">
<xsl:apply-templates select="$nodetree" mode="mode3">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@mode eq 'mode4'">
<xsl:apply-templates select="$nodetree" mode="mode4">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@mode eq 'mode5">
<xsl:apply-templates select="$nodetree" mode="mode5">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:when test="@mode eq 'mode6'">
<xsl:apply-templates select="$nodetree" mode="mode6">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="$nodetree" mode="modeX">
<xsl:with-param name="param1" tunnel="yes" select="$var1"/>
<xsl:with-param name="param2" tunnel="yes" select="$var2"/>
<xsl:with-param name="param3" tunnel="yes" select="$var3"/>
<xsl:with-param name="param4" tunnel="yes" select="$var4"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
...
</xsl:template>


can be reduced to:

<xsl:template name="prepare">
...
<xsl:call-template name="dispatch">
<xsl:with-param name="param1" tunnel="yes" select="...some value or node-set generating expression"/>
<xsl:with-param name="param2" tunnel="yes" select="...some other value or node-set generating expression"/>
<xsl:with-param name="param3" tunnel="yes" select="...some other other value or node-set generating expression"/>
<xsl:with-param name="param4" tunnel="yes" select="..another value or node-set generating expression"/>
</xsl:call-template>
...
</xsl:template>


<xsl:template name="dispatch">
...
<xsl:choose>
<xsl:when test="@mode eq 'mode1'"><xsl:apply-templates select="$nodetree" mode="mode1"></xsl:when
<xsl:when test="@mode eq 'mode2'"><xsl:apply-templates select="$nodetree" mode="mode2"></xsl:when
<xsl:when test="@mode eq 'mode3'"><xsl:apply-templates select="$nodetree" mode="mode3"></xsl:when
<xsl:when test="@mode eq 'mode4'"><xsl:apply-templates select="$nodetree" mode="mode4"></xsl:when
<xsl:when test="@mode eq 'mode5'"><xsl:apply-templates select="$nodetree" mode="mode5"></xsl:when
<xsl:when test="@mode eq 'mode6'"><xsl:apply-templates select="$nodetree" mode="mode6"></xsl:when
<xsl:otherwise><xsl:apply-templates select="$nodetree" mode="modeX"></xsl:otherwise>
</xsl:choose
...
<xsl:template>



Which already looks better, mostly since all modes in this example share the same tunneled parameters.
The xsl:choose in "dispatch" is still somewhat clunky and an additional template is required.
Therefore, I still propose that mode be made computable.


Regards,
ac




And there is here only 7 modes and 4 parameters, instead, if the apply-templates could be computed, I would have liked to possibly have something less redundant, for any number of modes and parameters, more like
...
<xsl:apply-templates select="$nodetree" mode="@mode">
<xsl:with-param name="param1" tunnel="yes" select="...some value or node-set generating expression"/>
<xsl:with-param name="param2" tunnel="yes" select="...some other value or node-set generating expression"/>
<xsl:with-param name="param3" tunnel="yes" select="...some other other value or node-set generating expression"/>
<xsl:with-param name="param4" tunnel="yes" select="..another value or node-set generating expression"/>
</xsl:apply-templates>
...


It seems that it could save space, variables, design time, run time, typos, errors, as well as ease maintenance and update (e.g adding mode7 and forgetting to add another xsl:when clause for it ...), while increasing readability.

Are there more elegant ways to handle mode selection? Can this be a useful use-case to support allowing "mode" to be computed somehow, in future XSLT updates?

Thank you,
ac

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.