in the main kupu.html document with the same ID.
Ordinarily, we'd use the onload handler to load and cache the XSLT.
For demonstration purposes, we leave it in the kupu.js file's
runTransform function. This allows you to change either the XML or
XSLT and press the button. You'll see the new results.
Notes
1. This is only a mild form of how it works in Kupu. For example,
we ignore IE in d9, and use a technique for merging DOMs that
only works in Firefox/Moz/Safari/Opera/everythingelse. :^)
2. Moving elements between documents (the response of the
transform vs. the main document) can be painful. First, IE
doesn't support it, so you have to do innerHTML. Second,
namespaces frequently cause baffling surprises. Note that the
XSLT tranform, near the top, specificies an output-method of
html, so that the namespace of the transform is the same as the
main document.
3. I removed the xmlns declaration on the element in the
XSLT. This is only for convenience: Mozilla comes up with some
annoying, though valid, namespace prefixes when left to its own
devices.
4. I cheated and used synchronous loading on the model and view.
Doing async requires a few lines extra for callback functions.
D10, Respond To Events
----------------------
We can now show how events work. When the user clicks in the
browser on a different library source, we move the "selection" from
one XML node to another.
First we need to get the mockup data ready. We start by making the
first library source selected, since that is what the user would
expect. We also choose one of the
nodes for the other
two libraries elements to be the selected resource. This
also means we need to copy some of the extra data to this
node.
The XSLT gets changed to have an onclick handler for each in the
left column. This onclick handler calls a JavaScript function named
"changeLibrary", passing in an identifier in the XML DOM for the
newly-clicked library. We also pass in the event object.
In the JS, we first make the model and view variables into globals,
so we can use them across functions. The comments in this JS
function explain the ideas.