|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Dynamic XSL Sorting - Is there a way like this?
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> You don't need to count the elements, only check for existence: <xsl:if test="HRISReport/Participants/Participant/Plans/Plan/ ContributionRateChanges/ContributionRateChange/RateChanges/RateChange"> <link rel='stylesheet' href='/stylesheet.css'/> <HTML> <HEAD> <TITLE>Deferral Pct Changes</TITLE> </HEAD> <BODY> <table class='datatable' cellspacing='1'> <tr> <td class='ttitle' colspan='13'>Deferral Pct Changes</td> </tr> <tr> <td class='theader' colspan='13'> From <xsl:value-of select="normalize-space(HRISReport/@StartDate)"/> - To <xsl:value-of select="normalize-space(HRISReport/@EndDate)"/> </td> </tr> <tr> <td class='theader'>SSN</td> <td class='theader'>Last Name</td> <td class='theader'>First Name</td> <td class='theader'>Participant Group</td> <td class='theader'>ID Code</td> <td class='theader'>HCE Code</td> <td class='theader'>Participation<br/>Date</td> <td class='theader'>Request Date</td> <td class='theader'>Contribution<br/>Acct</td> <td class='theader'>Old<br/>Percent</td> <td class='theader'>New<br/>Percent</td> <td class='theader'>Old<br/>Amount</td> <td class='theader'>New<br/>Amount</td> </tr> <xsl:for-each select="HRISReport/Participants/Participant/Plans/Plan/ContributionRateChanges/C ontributionRateChange/RateChanges/RateChange"> <xsl:sort select="@*[name(.)=$sortBy]"/> Please don't use TABs for indenting, but 2 or 4 spaces - this makes your mail/code more readable. The issue is the sort. If I use and hard code the following it works: <xsl:for-each select="HRISReport/Participants/Participant/Plans/Plan/ContributionRateChanges/C ontributionRateChange/RateChanges/RateChange"> <xsl:sort select="../../../../../../LastName"/> <xsl:sort select="../../../../../../@SSN"/> The problem are the different levels of your XML elements. Like you are navigating on the tree to the correct elements/attributes in the hard-coded version, you must do it in the parameterized version. I.e. you have to use something like '../../../../../../@SSN' as parameter for sorting. Problem: Dynamic evaluating of an XPATH expression isn't possible in pure XSLT 1, but using extension function evaluate() in many processors. If your sort elements are all on the same level, you can do something like <xsl:sort select="../../../../../../*[name()=$sortBy] | ../../../../../../@*[name()=$sortBy]"/> if their are no attributes and elements with the same name. But you will have a problem with your "multiple level sort possibilities". Maybe other people know a better solution than <xsl:sort select="(*|@* | ../*|../@* | ../../*|../../@* | ../../../*|../../../@* | ../../../../*|../../../../@* | ../../../../../*|../../../../../@* | ../../../../../../*|../../../../../../@*)[name() = $sortBy]"/> Regards, Joerg 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
|

Cart








