|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] XSL/XPath Dynamic sort key
I know I know, it's not possible. Well I've got this line working so far,
so I'm halfway through the "this is impossible in XSL" process so far.
First some params, then some XSL.
<xsl:param name="sort_select_lvl_1">author</xsl:param> <xsl:param name="sort_select_lvl_2">/</xsl:param> <xsl:param name="sort_select_lvl_3">last_name</xsl:param> <xsl:param name="sort_order">ascending</xsl:param> <xsl:param name="sort_data_type">text</xsl:param> <xsl:apply-templates select="document"> <xsl:sort select="*[name()=$sort_select_lvl_1]" data-type="{$sort_data_type}" order="{$sort_order}" /> </xsl:apply-templates> Now here's what I want. Sometimes I want to sort by uid, accesses, which works fine. Other times I want to sort by author/last_name. Now I can do this by changing the sort line to this... <xsl:sort select="*[name()=$sort_select_lvl_1]\*[name()=$sort_select_lvl_2]" data-type="{$sort_data_type}" order="{$sort_order}" /> But then it doesn't work for uid or accesses anymore because the "\" at the end of the string. If I remove the "\" i get a number expected error. So I've come up with half a way around it. I figure I will have lots of variables at the top, lvl_1 through 4 so that I can fill them all with parts of an xpath statement and then join them togather. So I try it and unfortunately xpath's concat does not let the sort select evaluate the xpath statement. In other words xsl:sort select="concat('author','/','last_name')" />
is not the same as
<xsl:sort select="author/last_name" />So how do I string togather the *[name()=$sort_select_lvl_1], one directly after the other? I set the defaults in the xslt above to reflect a reference to "author/last_name". Glimpse of XML <catalog> <document> <uid>2301</uid> <url>http://www.who.com/document.htm</url> <subject>General Stuff</subject> <abstract>This is an abstractabstract> <accesses>1</accesses> <age>4</age> <last_accessed date="20011229">12/29/2001</last_accessed> <author> <first_name>Peon</first_name> <last_name>lover</last_name> <serial>9A1551645</serial> </author> <owner> <first_name>Jolly</first_name> <last_name>Goose</last_name> <serial>123456</serial> </owner> <manager> <first_name>Someone</first_name> <last_name>Special</last_name> <serial>123456</serial> </manager> <supervisor> <first_name>Someone</first_name> <last_name>Important</last_name> <serial>123456</serial> </supervisor> </document> ... </catalog> Thanks in advance! Aaron _________________________________________________________________ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|






