[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Dynamically define number of xsl:sort stmts using
On 3/28/07, Angela Williams <Angela.Williams@xxxxxxxxxxxxxxxxxx> wrote:
Aha! Here's a way of sorting dynamically without extensions: <?xml version="1.0"?> <xsl:stylesheet version="2.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fn="fn"> <xsl:variable name="employees" select="/employees/employee"/> <xsl:variable name="sortValues" select="/employees/sort" as="xs:string+"/> <xsl:function name="fn:performSort" as="element()+"> <xsl:param name="list" as="element()+"/> <xsl:param name="sortKey" as="xs:string+"/> <xsl:variable name="sortedList" as="element()+"> <xsl:for-each select="$list"> <xsl:sort select="*[name() = $sortKey[1]]"/> <xsl:copy-of select="."/> </xsl:for-each> </xsl:variable> <xsl:sequence select="if ($sortKey[2]) then fn:performSort($sortedList, subsequence($sortKey, 2)) else $sortedList"/> </xsl:function> <xsl:template match="/"> <xsl:sequence select="fn:performSort($employees, $sortValues)"/> </xsl:template> </xsl:stylesheet> You call the performSort() function with a list of elements to sort, and a list of child element names to sort with, and it recursively sorts by each one. hope this helps, cheers andrew
|
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
|