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
If you're comfortable with XSLT but not with Javascript then you might like to look at Saxon-CE, which provides XSLT 2.0 in the browser with extension to handle user interaction events. There's a simple example which demonstrates how to sort tables in response to a mouse-click here:
http://www.saxonica.com/ce/doc/samples/booklist.xml
This is what I ended up doing and it works well!
HTML:there was a div for the xml document load
JAVASCRIPT
XML: I then had multiple xsl files where it specified a certain sort. Each function called a different style sheet.