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

Dynamic double sorting question

Subject: Dynamic double sorting question
From: Fei Xie <fxie27@xxxxxxxxx>
Date: Sat, 15 Mar 2003 18:39:00 -0800 (PST)
double sort
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

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.