Good morning, list -
My requirement is that I have an unknown number of sort conditions that I want
to apply to a for-each, for-each-group, or apply-templates construct.
Is there a way to dynamically define the number of <xsl:sort> statements to use
based on selecting parameters from an xml?
For example, <list> might have 0 to n <sort/> nodes:
<list>
<address>
<name/>
<street/>
<city/>
</address>
<!-- more address nodes -->
<sort order="1">name</sort>
<sort order="2">city</sort>
<!-- might have more sort nodes -->
</list>
If I have no nodes, I would want to omit the <xsl:sort> statement, etc...
I can think of the following theoretical solutions, but I don't know if they
are even possible:
1. (I know this doesn't work) Create multiple variables to evaluate the sort
value and then hardcode the same number of <xsl:sort> statements that may be
evaluating a null value for @select:
<snip>
<xsl:variable name=sort1 select="sort[(_at_)order="1"]/>
<xsl:variable name=sort2 select="sort[(_at_)order="2"]/>
<xsl:variable name=sort3 select="sort[(_at_)order="3"]/> <!-- empty -->
</snip>
<snip>
<xsl:for-each select="address">
<xsl:sort select="saxon:evaluate($sort1)/>
<xsl:sort select="saxon:evaluate($sort2)/>
<xsl:sort select="saxon:evaluate($sort3)/> <!-- error here -->
</xsl:for-each>
</snip>
2. Use xsl to select the sort nodes and then dynamically write and output the
template and for-each loop that uses the appropriate number of sort statements
- then how would I call it in the same stylesheet?
3. Write multiple templates using 0 to n sort statements and then call the
appropriate template based on the number of <sort/> nodes found? This doesn't
sound very elegant or practical to me, but might be the simplest...
Any suggestions?
Thanks!
Angela Williams
Channel Developer
The 401k Company
512-344-1547
--~------------------------------------------------------------------
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>
--~--