Subject: [xsl] Dynamic double sorting question From: Fei Xie <fxie27@xxxxxxxxx> Date: Sat, 15 Mar 2003 18:39:00 -0800 (PST) |
Hi all, I need to provide a sorting functionality where users can select the first and/or secondary sorting columns and specify their orders. I captured the sorting headers, sorting orders, and sorting datatype and stored them as parameters correctly. I get the correct sorting for most of the column headers except for the one for 'broken' (it doesn't seem to sort at all):-( Any help would be greatly appreciated. Many thanks in advance. Here are some simplified xml I worked on: <server ip="192.168.0.4:8080"> <num>0</num> <max>22</max> <rules> <rule name="broken">0</rule> </rules> </server> Here are some simplified xsl which performed sorting based on params: <!-- interpret the column head and some columns call for double sorting by itself, such as users (num first, max next, ^ as delimit) --> <xsl:template name="convert_path"> <xsl:param name="fieldname"/> <xsl:choose> <xsl:when test="$fieldname = 'users'">num^max</xsl:when> <xsl:when test="$fieldname = 'ip'">@ip</xsl:when> <xsl:when test="$fieldname = 'broken'">rules/rule[@name = 'broken']</xsl:when> <xsl:when test="$fieldname = 'any'">any</xsl:when> </xsl:choose> </xsl:template> <!-- double sort --> <xsl:template name="sort_field"> <!-- first sorting --> <xsl:param name="field1_path"> <xsl:call-template name="convert_path"> <xsl:with-param name="fieldname" select="$sort1"/> </xsl:call-template> </xsl:param> <!-- second sorting --> <xsl:param name="field2_path"> <xsl:call-template name="convert_path"> <xsl:with-param name="fieldname" select="$sort2"/> </xsl:call-template> </xsl:param> <xsl:choose> <xsl:when test="$field2_path = 'any' and not(contains($field1_path, '^'))"> <xsl:apply-templates select="$T_SERVERS"> <!-- this way doesn't work for "broken" field, but works for all other fields--> <xsl:sort select="*[name() = $field1_path] | @*[concat('@',name()) = $field1_path]" order="{$order1}" data-type="{$sort1_type}"/> <!-- this way works though for "broken" field though, but I don't use it because I need to keep it generic--> <!--<xsl:sort select="rules/rule[@name = 'broken']" order="{$order1}" data-type="{$sort1_type}"/>--> </xsl:apply-templates> </xsl:when> <!-- any suggestions of making this template shorter and more elegant are greatly appreciated --> <xsl:when test="$field2_path = 'any' and contains($field1_path, '^')"> <xsl:apply-templates select="$T_SERVERS"> <xsl:sort select="*[name()=substring-before($field1_path, '^')]" order="{$order1}" data-type="{$sort1_type}"/> <xsl:sort select="*[name()=substring-after($field1_path, '^')]" order="{$order1}" data-type="{$sort1_type}"/> </xsl:apply-templates> </xsl:when> <xsl:when test="contains($field1_path, '^')"> <xsl:apply-templates select="$T_SERVERS"> <xsl:sort select="*[name()=substring-before($field1_path, '^')]" order="{$order1}" data-type="{$sort1_type}"/> <xsl:sort select="*[name()=substring-after($field1_path, '^')]" order="{$order1}" data-type="{$sort1_type}"/> <xsl:sort select="*[name() = $field2_path] | @*[concat('@',name()) = $field2_path]" order="{$order2}" data-type="{$sort2_type}"/> </xsl:apply-templates> </xsl:when> <xsl:when test="contains($field2_path, '^')"> <xsl:apply-templates select="$T_SERVERS"> <xsl:sort select="*[name() = $field1_path] | @*[concat('@',name()) = $field1_path]" order="{$order1}" data-type="{$sort1_type}"/> <xsl:sort select="*[name()=substring-before($field2_path, '^')]" order="{$order2}" data-type="{$sort2_type}"/> <xsl:sort select="*[name()=substring-after($field2_path, '^')]" order="{$order2}" data-type="{$sort2_type}"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="$T_SERVERS"> <xsl:sort select="*[name() = $field1_path] | @*[concat('@',name()) = $field1_path]" order="{$order1}" data-type="{$sort1_type}"/> <xsl:sort select="*[name() = $field2_path] | @*[concat('@',name()) = $field2_path]" order="{$order2}" data-type="{$sort2_type}"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </xsl:template> Thanks, -FA __________________________________________________ Do you Yahoo!? Yahoo! Web Hosting - establish your business online http://webhosting.yahoo.com XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] use of xsl:key in cross-r, Xiaocun Xu | Thread | [xsl] short question regarding xsl:, Robert P. J. Day |
Re: [xsl] use of xsl:key in cross-r, Wendell Piez | Date | Re: [xsl] Embedding XSL in JavaScri, Joe Fawcett |
Month |