Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8728905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:44:08+00:00 2026-06-13T08:44:08+00:00

I would like to know the simplest way to sort an xml/xslt table by

  • 0

I would like to know the simplest way to sort an xml/xslt table by clicking associated buttons. I’m pretty familiar with xslt but very new to Javascript so go easy on me.

I’ve looked at many examples on the internet but it seems like nothing really fits what I’m trying to do or perhaps my coding skills just aren’t up to par.

I might be way off but I was thinking something along the lines of…

xslt:

<button onclick="title()">sort by title</button>
<!--some xsl code-->
<xsl:for each select="record">
<xsl:sort id="title" select="dates/year"/>
<!--more xsl code-->

Javascript:

function title() {
document.getElementById(title).select="titles/title";
}

I’m also not exactly clear on where to put the Javascript code. I’ve already got a .js file that displays my xml & xsl files as an html. Can I put this code there? Or do I need inline script on my xsl file? I’ve seen many ways of attaching Javascript to an xsl file, but I’m not sure which way is best for my purposes

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T08:44:09+00:00Added an answer on June 13, 2026 at 8:44 am

    This is what I ended up doing and it works well!

    HTML:there was a div for the xml document load

    <button type="button" id="sorttitle" onclick="sorttitle()">sort by title</button>
    <button type="button" id="sortauthor" onclick="sortauthor()">sort by author</button>
    <button type="button" id="sortyear" onclick="sortyear()">sort by year</button>
    <button type="button" id="sortpublisher" onclick="sortpublisher()">sort by publisher</button>
    

    JAVASCRIPT

    function sorttitle(){
    document.getElementById("sortauthor").style.backgroundColor="#000";
    document.getElementById("sortyear").style.backgroundColor="#000";
    document.getElementById("sortpublisher").style.backgroundColor="#000";
    document.getElementById("sorttitle").style.backgroundColor="#666";
    xsl=loadXMLDoc("sorttitle.xsl");
    if (window.ActiveXObject)
      {
      sortedDocument=xml.transformNode(xsl);
      document.getElementById('content').innerHTML=sortedDocument;
    }
    else {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      sortedDocument = xsltProcessor.transformToFragment(xml,document);
      document.body.replaceChild(sortedDocument,document.getElementById('content'));
    }}
    
    function sortauthor(){
    document.getElementById("sorttitle").style.backgroundColor="#000";
    document.getElementById("sortyear").style.backgroundColor="#000";
    document.getElementById("sortpublisher").style.backgroundColor="#000";
    document.getElementById("sortauthor").style.backgroundColor="#666";
    xsl=loadXMLDoc("sortauthor.xsl");
    if (window.ActiveXObject)
      {
      sortedDocument=xml.transformNode(xsl);
      document.getElementById('content').innerHTML=sortedDocument;
    }
    else {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      sortedDocument = xsltProcessor.transformToFragment(xml,document);
      document.body.replaceChild(sortedDocument,document.getElementById('content'));
    }}
    
    function sortyear(){
    document.getElementById("sorttitle").style.backgroundColor="#000";
    document.getElementById("sortauthor").style.backgroundColor="#000";
    document.getElementById("sortpublisher").style.backgroundColor="#000";
    document.getElementById("sortyear").style.backgroundColor="#666";
    xsl=loadXMLDoc("sortyear.xsl");
    if (window.ActiveXObject)
      {
      sortedDocument=xml.transformNode(xsl);
      document.getElementById('content').innerHTML=sortedDocument;
    }
    else {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      sortedDocument = xsltProcessor.transformToFragment(xml,document);
      document.body.replaceChild(sortedDocument,document.getElementById('content'));
    }}
    
    function sortpublisher(){
    document.getElementById("sorttitle").style.backgroundColor="#000";
    document.getElementById("sortauthor").style.backgroundColor="#000";
    document.getElementById("sortyear").style.backgroundColor="#000";
    document.getElementById("sortpublisher").style.backgroundColor="#666";
    xsl=loadXMLDoc("sortpublisher.xsl");
    if (window.ActiveXObject)
      {
      sortedDocument=xml.transformNode(xsl);
      document.getElementById('content').innerHTML=sortedDocument;
    }
    else {
      xsltProcessor=new XSLTProcessor();
      xsltProcessor.importStylesheet(xsl);
      sortedDocument = xsltProcessor.transformToFragment(xml,document);
      document.body.replaceChild(sortedDocument,document.getElementById('content'));
    }}
    

    XML: I then had multiple xsl files where it specified a certain sort. Each function called a different style sheet.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know what the simplest/best way for obtaining information about the
I would like to know the simplest and most effective way to open and
i would like know some reference. I know i can googling it. but prefer
I would like to know the best way to delete records from a live
I'd like to know the simplest way, in Java, to get a list of
I would like to know the simplest solution to changing the underscores of my
I would like to ask about best practices or the simplest way possible of
I would like to know the best way to deal with long running processes
Would like to know what a programmer should know to become a good at
Would like to know the c# code to actually retrieve the IP type: Static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.