This snippet demonstrates uses the "Taliban Singles Online" dating application to demonstrate some of most common functionality found in business applications.
b) Sorting by column header (ascending or descending) and
c) Highlighting the row as the mouse moves over it. As with my other "Redneck Employee" snippet, it uses a behavior .htc file to do the highlighting and column sorting. However, this snippet also demonstrates how to use XML/XSLT to filter the data data island in the page.
Check it out in action
are shown below. The source code is documented as well and will
explain it all:
a) To add the ability to highlight the current row and "sort by clicking on the column header" you will need to simply add the behavior to the table as follows:<TABLE style="BEHAVIOR: url(TableSortAndHighlight.htc)" ....>
b) To indication which xml attribute in the xml document is sorted when
you click on the column header, just add the "SortField" attribute
to the html table column. Examples are as follows:
<TBODY>TR><TR><TD .... SortField="FirstName" ..... <TD>State..... Yes, this assumes that the xml document is attribute normalized, but it is not a very big leap to modify to handle <BR>xml documents that are element normalized.
c) The Filtering is done via passing parameters to an XSLT file using VBScript. The code is shown below:<BR><BR>
function vbFilterTable(strLocation, strOccupation, strType)
dim objXSL, objXML, objTemplate, objProcessor, strHTML
Set objXML = CreateObject("Msxml2.FreeThreadedDOMDocument")
Set objXSL = CreateObject("Msxml2.FreeThreadedDOMDocument")
'Load the XML document
objXML.async = False
'Load the XSL document
objXSL.async = False
'Create an instance of our XSL Template object
Set objTemplate = CreateObject("MSXML2.XSLTemplate")
'Create an instance of our stylesheet object using our recently loaded XSLT
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
objProcessor.input = objXML
'Now, finally we can add any parameters that we require to our Template
'In this example, we are setting the drinktype = "house"
objProcessor.AddParameter "location", strLocation
objProcessor.AddParameter "occupation", strOccupation
objProcessor.AddParameter "type", strType
'Last but not least we do our transformation
'Store the results of the output into a string.
strXML = objProcessor.output
'Load up an XML DOM object from the recent XML output
'Select only the "employees" elements from our document object
'Load our Data Island using our new XML object