One problem that keeps popping up when creating forms with XForms is the lack of sorting. This is an example for how it is possible to sort an instance using a XSLT stylesheet in Firefox. The following model contains two instances. The first instance is the one we will sort and the second instance contains the XSLT stylesheet we will use to perform the sort. B-item 2001-05-03   A-item 2005-05-03   Z-item 2003-05-03   D-item 2002-05-03                     To perform the sort we will use the following JavaScript which will load the second instance into the Firefox stylesheet engine, then take the first instance make the transformation which will produce the sorted instance. Then the transformed instance is inserted into the model and a rebuild, recalculate, revalidate and refresh is performed. function sort_instance(id) { // We get the instance element var instanceElement = document.getElementById(id); if (instanceElement!=null) { // XForms exposes the retrival of the instance document from the model element which *should* // be the parent for the instance element. var instance = instanceElement.parentNode.getInstanceDocument(id); if (instance!=null) { // Now creating the stylesheet, for this example the stylesheet document is also an instance // by it can be loaded from many difference sources var xslDom = instanceElement.parentNode.getInstanceDocument('stylesheet'); // create an XSLTProcessor and attach the stylesheet var processor = new XSLTProcessor() processor.importStylesheet(xslDom); // now we do the sorting transformation var resultDom = processor.transformToDocument(instance, instance); // we then move the result info the instance dom instance.removeChild(instance.documentElement); instance.appendChild(resultDom.documentElement); // and performs the updates for XForms instanceElement.parentNode.rebuild(); instanceElement.parentNode.recalculate(); instanceElement.parentNode.revalidate(); instanceElement.parentNode.refresh(); } } } The idea of having the stylesheet in an instance makes it possible to change the behavior of the sorting by binding controls to it and change stuff like XPath expressions and other XSLT syntax. This example is based upon the sample on [[1]http://landwehr.dk/blog/] Next Page: Mobile XForms | Previous Page: Google Maps Home: XForms
{'wiki_source': 'wikibooks', 'other_info': "{'content_model': 'wikitext', 'language': 'en', 'title': 'XForms/Sorting using XSLT', 'type': 'text'}"}