Dynamic sorting method in XSLT

Source: Internet
Author: User

This solution uses the built-in intent template object in the DOM;

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> </title>
<Meta name = "generator" content = "Microsoft Visual Studio. NET 7.1">
<Meta name = progid content = visualstudio. html>
<Meta name = originator content = "Microsoft Visual Studio. NET 7.1">
</Head>
<Body>
<Div id = odiv> </div>
<Script language = JavaScript>
VaR XSLT = new activexobject ("msxml2.20.template ");
VaR synchronized Doc = new activexobject ("msxml2.freethreadeddomdocument ");
VaR publish proc;
Optional Doc. async = false;
Using Doc. Load ("csdn0030.xsl ");
XSLT. stylesheet = javasdoc;
VaR xmldoc = new activexobject ("msxml2.domdocument ");
Xmldoc. async = false;
Xmldoc. Load ("csdn0030.xml ");
Export proc = XSLT. createprocessor ();
Export Proc. Input = xmldoc;
Function _ trans (){
Using Proc. Transform ();
Odiv. innerhtml = export Proc. output;
}
Function _ onchange (OBJ, key ){
Using Proc. addparameter (Key, OBJ [obj. selectedindex]. value );
_ Trans ();
}
_ Trans ();
</SCRIPT>
Sorting field:
<Select id = 'key' onchange = "_ onchange (this, 'key')">
<Option value = ID> id </option>
<Option value = Name> name </option>
</SELECT>
Sorting type:
<Select id = "select1" onchange = "_ onchange (this, 'order')" name = "select1">
<Option value = descending> descending </option>
<Option value = ascending> ascending </option>
</SELECT>
</Body>
</Html>

Csdn0030.xml:
<? XML version = "1.0" encoding = "UTF-8"?>
<Root>
<User>
<ID> 1 </ID>
<Name> SSM </Name>
</User>
<User>
<ID> 4 </ID>
<Name> assm </Name>
</User>
<User>
<ID> 3 </ID>
<Name> CSSM </Name>
</User>
<User>
<ID> 2 </ID>
<Name> bssm </Name>
</User>
<User>
<ID> 5 </ID>
<Name> essm </Name>
</User>
</Root>

Csdn0030.xsl
<? XML version = "1.0" encoding = "UTF-8"?>
<XSL: stylesheet version = "1.0" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform">
<XSL: Param name = "key"> id </XSL: param>
<XSL: Param name = "order"> descending </XSL: param>
<XSL: template match = "/">
<XSL: For-each select = "// user">
<XSL: Sort select = "* [name () = $ key]" Order = "{$ order}"/>
<XSL: value-of select = "ID"/> <br/>
<XSL: value-of select = "name"/>
<HR/>
</XSL: For-each>
</XSL: Template>
</XSL: stylesheet>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.