Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How to sort on currency and date field - sample source included

From: "Han" <hp4444@------.---.----->
To: NULL
Date: 11/3/2004 12:10:00 PM
Current version of XSLT and XPath 1.0 don't support datetime and currency 
formats.

"Noel" <nospam@n...> wrote in message 
news:u6QDJJJwEHA.1396@t......
> Hi,
>
> I would like to sort on currency and date field using code below (it works
> like a champ for other datatypes). Can someone show me how? Please find
> below the sample source that works for other datatypes. I would like to 
> get
> this modified to sort on currency and date fields as well.
>
> Thanks in advance,
> Noel
>
> --------------------- 
> TableSorted.xsl:
> --------------------- 
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> version="1.0"><xsl:output method="xml"/>
>
> <xsl:param name="sortorder" select="'descending'"/>
> <xsl:param name="sortfield" select="'xxx'"/>
>
> <xsl:template match="/">
>    <root>
>    <xsl:for-each select="root/data" >
>    <xsl:sort select="@*[name()=$sortfield]" order="{$sortorder}" />
>        <data>
>            <xsl:for-each select="@*" >
>                <xsl:attribute name='{name()}'> <xsl:value-of
> select="."/></xsl:attribute>
>            </xsl:for-each>
>        </data>
>    </xsl:for-each>
>    </root>
> </xsl:template>
> <xsl:template match="data">
>    <data>
>        <xsl:apply-templates/>
>    </data>
> </xsl:template>
> </xsl:stylesheet>
>
> --------------------- 
> Employees.xml:
> --------------------- 
> <root>
>    <data dataID="1" FirstName="Buddy" LastName="Thornton"
> ResidenceType="Trailor Home" Address="507 - 20th Ave. E.Apt. 2A"
> City="Huntington" State="West Virginia" ZipCode="98122" Country="USA"
> Hobbies="Shootin stuff, Cow Tipping" HomePhone="(206) 555-9857"
> EmpPhoto="images/emp10.jpg" Salary="$12, 00,000.00" DOB="12/31/1976" />
>    <data dataID="2" FirstName="Emma Sue" LastName="Fuller"
> ResidenceType="Trailor Home" Address="908 W. Capital Way" City="Tacoma"
> State="West Virginia" ZipCode="98401" Country="USA"  Hobbies="Smoking"
> HomePhone="(206) 555-9482"  EmpPhoto="images/emp2.jpg" Salary="$1,000.60"
> DOB="12/31/1975" />
>    <data dataID="3" FirstName="Linda Sue" LastName="Leverling"
> ResidenceType="Trailor Home" Address="722 Moss Bay Blvd." City="Kirkland"
> State="West Virginia"  ZipCode="98033" Country="USA"  Hobbies="Cooking,
> cleaning" HomePhone="(206) 555-3412" EmpPhoto="images/emp11.jpg"
> Salary="$20,000.00" DOB="12/01/1976" />
>    <data dataID="4" FirstName="Bubba" LastName="Smith"
> ResidenceType="Trailor Home" Address="4110 Old Redmond Rd."
> City="Huntington"  State="West Virginia"  ZipCode="98052" Country="USA"
> Hobbies="Fishin, Shootin stuff" HomePhone="(206) 555-8122"
> EmpPhoto="images/emp12.jpg" Salary="$12.00" DOB="01/12/1975" />
>    <data dataID="5" FirstName="Jim Bob" LastName="Buchanan"
> ResidenceType="Trailor Homer" Address="14 Garrett Hill" City="Huntington"
> State="West Virginia" Country="UK" ZipCode="34323"  Hobbies="Explosives,
> drinkin" HomePhone="(71) 555-4848"  EmpPhoto="images/emp5.jpg"
> Salary="$1,00,000.99" DOB="01/01/1974" />
>    <data dataID="6" FirstName="Billy Joe" LastName="Thomson"
> ResidenceType="Trailor Home" Address="Coventry House Miner Rd."
> City="Huntington"  State="West Virginia" ZipCode="23423" Country="UK"
> Hobbies="Fishin, Shootin stuff" HomePhone="(71) 555-7773"
> EmpPhoto="images/emp6.jpg" Salary="$12,012.96" DOB="12/31/1971" />
>    <data dataID="7" FirstName="Suzy Bob" LastName="Johnsonless"
> ResidenceType="Trailor Home" Address="Edgeham Hollow Winchester Way"
> City="Huntington"  State="West Virginia" ZipCode="23424" Country="UK"
> Hobbies="Sleeping around" HomePhone="(71) 555-5598"
> EmpPhoto="images/emp7.jpg" Salary="$122.96" DOB="11/30/1979" />
>    <data dataID="8" FirstName="Henry" LastName="Callahan"
> ResidenceType="Trailor Home" Address="4726 - 11th Ave. N.E." 
> City="Seattle"
> State="West Virginia"  ZipCode="98105" Country="USA"  Hobbies="Fishin,
> Shootin stuff" HomePhone="(206) 555-1189"  EmpPhoto="images/emp8.jpg"
> Salary="$1,12,012.96" DOB="12/31/1970" />
>    <data dataID="9" FirstName="Cindy Sue" LastName="Scallawagger"
> ResidenceType="Trailor Home" Address="7 Houndstooth Rd." 
> City="Huntington"
> State="West Virginia"  ZipCode="32432" Country="UK"  Hobbies="Eating 
> sweets"
> HomePhone="(71) 555-4444"  EmpPhoto="images/emp9.jpg" Tmp="$10.25"
> DOB="12/31/1971" />
> </root>
>
> --------------------------- 
> TableSortAndHighlight.htc:
> --------------------------- 
>
> <public:event     name="onrowselect" ID=rowSelect />
> <public:property name="HL_CallBack" />
> <public:attach   event="ondetach" ONEVENT="cleanup()" />
> <public:attach   event=onreadystatechange onevent="onReadyStateChange()">
>
> <script language=jscript>
>
> var currRow = -1;
> var selRow = -1;
> var HColor="cyan";
> var    SColor = "#FFFFCC";
>
>
>
> if (element.tagName == 'TABLE')
> {
>    element.attachEvent('onmouseover', onMouseOver);
>    element.attachEvent('onmouseout', onMouseOut);
>    element.attachEvent('onclick', onClick);
>    element.attachEvent('onreadystatechange', onReadyStateChange);
> }
> else
> {
>    alert("Error: tablehl not attached to a table element");
> }
>
>
> function cleanup() {
>    try {
>        hilite(-1);
>
>        element.detachEvent('onmouseover', onMouseOver);
>        element.detachEvent('onmouseout', onMouseOut);
>        element.detachEvent('onclick', onClick);
>        element.detachEvent('onreadystatechange', onReadyStateChange);
>    }
>    catch (error) {
>        alert("cleanup() in tablehl.htc caused the following error: " +
> error.description)
>    }
> }
>
>
> function onClick() {
>    try {
>        srcElem = window.event.srcElement;
>
>
>        //crawl up the tree to find the table row
>        while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE" &&
> srcElem.tagName != "TH") {
>            srcElem = srcElem.parentElement;
>        }
>
>
>        if(srcElem.tagName == "TH")
>            {
>            SortJS();
>            return;
>            }
>
>
>
>        if(srcElem.tagName != "TR") return;
>
>        if(srcElem.rowIndex <= 0 ) return;
>
>        if (selRow != -1) selRow.runtimeStyle.backgroundColor = '';
>
>        srcElem.runtimeStyle.backgroundColor = SColor;
>        selRow = srcElem;
>
>        var oEvent     = createEventObject();
>        oEvent.selected = selRow;
>        rowSelect.fire(oEvent);
>
>    }
>    catch (error) {
>        alert("onClick() in tablehl.htc caused the following error: " +
> error.description)
>    }
> }
>
>
> function onMouseOver() {
>    try {
>        srcElem = window.event.srcElement;
>        //crawl up to find the row
>        while (srcElem.tagName != "TR" && srcElem.tagName != "TABLE")
>            srcElem = srcElem.parentElement;
>
>        if(srcElem.tagName != "TR") return;
>
>        if (srcElem.rowIndex >= 1)
>            hilite(srcElem);
>        else
>            hilite(-1);
>    }
>    catch (error) {
>        alert("onMouseOver() in tablehl.htc caused the following error: " +
> error.description)
>    }
> }
>
> function onMouseOut() {
>    try {
>        // Make sure we catch exit from the table
>        hilite(-1);
>    }
>    catch (error) {
>        alert("onMouseOut() in tablehl.htc caused the following error: " +
> error.description)
>    }
> }
>
> function hilite(newRow) {
>    try {
>        if (HColor != null ) {
>            if (currRow != -1 && currRow!=selRow) {
>                currRow.runtimeStyle.backgroundColor = '';
>            }
>
>            if (newRow != -1 && newRow!=selRow) {
>                newRow.runtimeStyle.backgroundColor = HColor;
>            }
>        }
>        currRow = newRow;
>    }
>    catch (error) {
>        alert("hilite() in tablehl.htc caused the following error: " +
> error.description)
>    }
> }
>
> function onReadyStateChange() {
>    try {
>        if (element.readyState == "complete") {
>            if (String(HL_CallBack).length > 0) {
>                if (HL_CallBack != 'null') {
>                    eval(HL_CallBack);
>                }
>            }
>        }
>    }
>    catch (error) {
>        alert("onReadyStateChange() in tablehl.htc caused the following
> error: " + error.description)
>    }
> }
>
> function SortJS()
> {
>    var nLastCol = element.document.all.thdr.length;
>    var    srcElem = window.event.srcElement;
>    var strSortOrder = "";
>    var strSortField = srcElem.SortField;
>
>    //Store away the current class name before it gets reset
>    strCurrClass = srcElem.className;
>
>    for (var n=0; n<nLastCol; n++)
>
>        {element.document.all.thdr(n).className = "SortingGridUp";
>        }
>
>
>    if (strCurrClass == "SortingAscending")
>        {
>        srcElem.className = "SortingDescending";
>        strSortOrder = "descending";
>        }
>    else
>        {
>        srcElem.className = "SortingAscending";
>        strSortOrder = "ascending";
>        }
>
>
>
> //        'Now, sort the data in our Data Island
>        SortPickList(strSortField, strSortOrder);
> //
>
>
>
> }
>
> </script>
>
> <script language="vbscript">
>
> function SortPickList(strSortField, strSortOrder )
>
>        dim objXSL, objXML, objTemplate, objProcessor, strHTML, 
> strDrinkType
>
>        'Since we are using the Template object, we will be using
> FreeThreaded DOM  documents.
> '        Set objXML = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
> '        Set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument.3.0")
>
>        Set objXML = CreateObject("Msxml2.FreeThreadedDOMDocument")
>        Set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument")
>
>        'Load the XML document
>        objXML.async = False
>        objXML.Loadxml xmlDSO.xml
>
>        'Load the XSL document
>        objXSL.async = False
>        objXSL.Loadxml  xslSorted.xml
>
>        'Create an instance of our XSL Template object
>        'Set objTemplate = CreateObject("MSXML2.XSLTemplate.3.0")
>        Set objTemplate = CreateObject("MSXML2.XSLTemplate")
>
>        'Create an instance of our stylesheet object using our recently
> loaded XSLT document
>        Set objTemplate.stylesheet = objXSL
>
>        'Create an instance of our Processor object
>        Set objProcessor = objTemplate.createProcessor
>
>        'Define the input object for our object equal to our recently 
> loaded
> XML document
>        objProcessor.input = objXML
>
>        'Now, finally we can add any parameters that we require to our
> Template processor
>        'In this example, we are setting the drinktype = "house"
>        objProcessor.AddParameter "sortfield", strSortField
>        objProcessor.AddParameter "sortorder", strSortOrder
>
>        'Last but not least we do our transformation
>        objProcessor.Transform
>
>        'Store the results of the output into a string.
>        strXML = objProcessor.output
>
>        'Load up an XML DOM object from the recent XML output
>        objXML.loadxml strXML
>
>        'Select only the "employees" elements from our document object
>        objXML.selectNodes("//ROOT")
>
>        'Load our Data Island using our new XML object
>        xmlDSO.loadxml  objXML.xml
>
>
>
>    end function
>
> </script>
>
>
> --------------------------- 
> Employees.htm
> --------------------------- 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
>
>
> <!-- 
> AUTHOR: David Silverlight
> Email: HeadGeek@x...
> Shameless Plug: Yes I am a consultant who is always looking for cool
> projects.
> Phone: (877) XML-GURU
>
> Description:  This code snippet demonstrates how to add Sorting and
> Highlighting to a DataBound HTML table.  Yes, it
> will not work in anything except an IE Browser and No, it does not do any
> updates to a database.  That functionality
> is outside of the scope of this snippet.  Enjoy.
> -->
>
>
> <head>
>    <title>Employee Listing</title>
>    <link href="mainstyle.css" rel="stylesheet">
>    <meta name="vs_targetSchema"
> content="http://schemas.microsoft.com/intellisense/ie5">
> </head>
>
> <body>
> <form method="post" action="" name="frmData">
>
> <div class="MainHeader" style="POSITION: absolute; TOP: 19px; " >Employee
> Listing</div>
> <div id="divHeader" style="Z-INDEX: 34; LEFT: 29px; WIDTH: 703px; 
> POSITION:
> absolute; TOP: 211px; HEIGHT: 149px">
>
>
> <!-- The  table below is kept seperated and is used as a header table. 
> The
> reason for this is to allow the datarows to scroll while
> the header row remains fixed.  Yes, it is a bit of extra work and it
> requires effort to make sure that the column widths are the same,
> but it is a nice effect.
>
> Note also that the sorting functionality is handled as a behavior.  If you
> search for a reference to a javascript or VBScript file
> in this page, you will not find it.  All of the sorting code is embedded 
> in
> the TableSortAndHighlight.htc file.  As long as the xml
> source has a root/data structure (see the attached employees.xml file to 
> see
> what I mean), this will work like a champ.  A more
> generic version of the XSLT file is coming soon(maybe).-->
>
>
> <table id="tblHeader" width="702" cellpadding="0" cellspacing="0" 
> border="1"
> bordercolor="#2d1663" style="LEFT: -1px; TOP: 0px; BEHAVIOR:
> url(TableSortAndHighlight.htc)">
>     <tr class="SortingGridUp">
>        <th id="thdr" width="59"   SortField="FirstName">FirstName</td>
>        <th id="thdr" width="64"   SortField="LastName">LastName</td>
>        <th id="thdr" width="69"
> SortField="ResidenceType">ResidenceType</td>
>        <th id="thdr" width="49"   SortField="ResidenceType">City</td>
>        <th id="thdr" width="67"   SortField="State">State</td>
>        <th id="thdr" width="40"   SortField="ZipCode">Zip</td>
>        <th id="thdr" width="139" SortField="Hobbies">Hobbies</td>
>        <th id="thdr" width="40"   SortField="Salary">Salary</td>
>        <th id="thdr" width="40"   SortField="DOB">DOB</td>
>     </tr>
> </table>
>
>
> <!-- The following table is displays the data rows.  Note that a "row
> highlighting" behavior is embedded in the datatable below.
>  Since Highlighting the row as you mouseover it is a very common
> characteristic of HTML tables, this makes life much easier
>  because you do not have to embed all of the highlighting code in each
> page.  Instead, just attach the TableHL.htc behavior to
>  your table.
> -->
>
>
> <div name="CustomerList" style="LEFT: 1px; OVERFLOW: scroll; WIDTH: 702px;
> TOP: 14px; HEIGHT: 132px">
>
> <table datasrc="#xmlDSO" style="BEHAVIOR: url(TableSortAndHighlight.htc)"
> LANGUAGE="javascript" class="DataTable" width="712" border="0"
> cellpadding="0" cellspacing="0" border="1">
>
> <tr onclick="CurrentRecord()">
>    <td width="59" align="left" height="15"><span datafld="FirstName"
> class="DataCol"></span></td>
>    <td width="64" align="left" height="15"><span datafld="LastName"
> class="DataCol"></span></td>
>    <td width="69" align="left" height="15"><span datafld="ResidenceType"
> class="DataCol"></span></td>
>    <td width="49" align="left" height="15"><span datafld="City"
> class="DataCol"></span></td>
>    <td width="67" align="left" height="15"><span datafld="State"
> class="DataCol"></span></td>
>    <td width="40" align="left" height="15"><span datafld="ZipCode"
> class="DataCol"></span></td>
>    <td width="139" align="left" height="15"><span datafld="Hobbies"
> class="DataCol"></span></td>
>    <td width="40" align="left" height="15"><span datafld="Salary"
> class="DataCol"></span></td>
>    <td width="40" align="left" height="15"><span datafld="DOB"
> class="DataCol"></span></td>
> </tr>
> </table>
>                </div>
>            </div>
>
>
> <!-- Below are the HTML Data Fields that highlight the data on the current
> record and allow you to update them via  INPUT elements -->
>
>
> <div id="main" style="LEFT: 0px; WIDTH: 759px; POSITION: absolute; TOP:
> 410px; HEIGHT: 29px" tabIndex="11">
> <div id="divDataFields" style="LEFT: 0px; WIDTH: 710px; POSITION: 
> absolute;
> TOP: -356px; HEIGHT: 27px">
>   <table  >
>      <tr>
>         <td>
>            FirstName<input id="txtFirstName"  DATASRC="#xmlDSO"
> DATAFLD="FirstName" style="WIDTH: 100px;">
>            LastName<input id="txtLastName"  DATASRC="#xmlDSO"
> DATAFLD="LastName" style="WIDTH: 100px;">
>         </td>
>      </tr>
>      <tr>
>         <td>
>        City <input id="txtCity" DATASRC="#xmlDSO" DATAFLD="City"
> style="WIDTH: 93px">
>        State<input id="txtState" DATASRC="#xmlDSO" DATAFLD="State"
> style="WIDTH: 100px;">
>        ZipCode<input id="txtZipCode" DATASRC="#xmlDSO" DATAFLD="ZipCode"
> style="WIDTH: 60px;">
>         </td>
>      </tr>
>      <tr>
>         <td>
>            Address<input id="txtAddress" DATASRC="#xmlDSO"
> DATAFLD="Address" style="WIDTH: 100px;">
>            Hobbies<input id="txtZipCode" DATASRC="#xmlDSO"
> DATAFLD="Hobbies"  style="WIDTH: 150px;">
>     </td>
>      </tr>
>      <tr>
>         <td>
>          Home Phone <input id="Text3" DATASRC="#xmlDSO" 
> DATAFLD="HomePhone"
> style="WIDTH: 93px;" NAME="Text3">
>              Home Type <input id="Text4" DATASRC="#xmlDSO"
> DATAFLD="ResidenceType" style="WIDTH: 93px; " NAME="Text4">
>     </td>
>      </tr>
>      <tr>
>         <td>
>            Salary<input id="txtAddress" DATASRC="#xmlDSO" DATAFLD="Salary"
> style="WIDTH: 100px;">
>            DOB<input id="txtZipCode" DATASRC="#xmlDSO" DATAFLD="DOB"
> style="WIDTH: 100px;">
>         </td>
>      </tr>
> </table>
> </div>
>
>
> <!-- Last but not least are the buttons that basically do not do anything.
> If you click on them, they will tell you.  -->
> <div id="divPhoto" style="LEFT: 404px; WIDTH: 217px; POSITION: absolute;
> TOP: -392px; HEIGHT: 231px">
>      <img id="imgEmp" style="LEFT: -1px;  WIDTH: 227px;  TOP: 0px; 
> HEIGHT:
> 186px" dataSrc="#xmlDSO" tabIndex="10" Datafld="EmpPhoto" name="State"
> size="2" height="200" width="200"></div>
>
> <div id="divSortType" style="LEFT: 33px; WIDTH: 679px; POSITION: absolute;
> TOP: -48px; HEIGHT: 34px">
>   <INPUT type="button" value="Add" id="btnAdd" name="btnAdd"
> onclick="DisplayDemoMessage" Language="VBScript">
>   <INPUT type="button" value="Modify" id="btnUpdate" name="btnModify"
> onclick="DisplayDemoMessage" Language="VBScript">
>   <INPUT type="button" value="Delete" id="btnDelete" name="btnDelete"
> onclick="DisplayDemoMessage" Language="VBScript">
> </div>
>
>            </div>
>        </form>
> <!-- Below are the actual Data Islands that hold the xml file and xsl
> Sorting stylesheet.  Although a hardcoded xml file is being
> used here, the logic will apply even if the xml is dynamically generated
> from a table. The names of the data islands are
> important, however. -->
>
> <xml id="xslSorted" src="TableSorted.xsl"></xml>
> <xml id="xmlDSO" src="Employees.xml"></xml>
>
>
> <!-- Last but not least, the javascript code is the only javascript that 
> you
> will see in this page.  Look ma, no includes! -->
>
> <script language="JavaScript">
>    function DisplayDemoMessage(){
>    alert("Note: These buttons do not do anything in this snippet.  Adding,
> Modifying and Deleting are not demonstrated in this example.  The purpose 
> of
> this example is to illustrate Sorting and highlighting of Data Islands 
> using
> behaviors.");
> }
>
>   function CurrentRecord(){
>    alert(window.event.srcElement.recordNumber);
>    var iNum = window.event.srcElement.recordNumber;
>                    xmlDSO.recordset.AbsolutePosition = iNum;
>            }
>
>        </script>
>    </body>
> </html>
>
> 



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent