<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<form>
<input onkeyup="callTemplate('myTemplate', [{ name: 'a', value: 1, type: 'int'}, { name: 'b', value: 2, type: 'int'}]);" />
</form>
</body>
</html>
/* Dynamic creation of SEF constructs to implement
* a simple form of <xsl:call-template/>
*/
function callTemplate(name, parameters) {
// only integer parameters for now! could also use <str val=""/>
var paramXml = parameters.map(function(parameter) {
// TODO var type = parameter.type; // can be 'int' or 'str', check this
return `<withParam name="${parameter.name}" flags="c" as="xs:integer">
<int val="${parameter.value}"/>
</withParam>`
}).join();
var callT = `<?xml version="1.0" encoding="UTF-8"?>
<callT role="action" vn="31" baseUri="husky.xsl"
ns="xsl=http://www.w3.org/1999/XSL/Transform fn=http://www.w3.org/2005/xpath-functions ixsl=http://saxonica.com/ns/interactiveXSLT xs=http://www.w3.org/2001/XMLSchema husky=http://nl.ebpi.husky array=http://www.w3.org/2005/xpath-functions/array"
line="12" name="${name}" bSlot="0">
${paramXml}
</callT>`;
var parser = new DOMParser();
var callDoc = parser.parseFromString(callT, "text/xml").documentElement;
var output = SaxonJS.U.evaluate(callDoc, window.context); // reuse context
var principal = output.next();
console.log(principal);
return principal;
}
window.onload = function() {
var options = {
stylesheetLocation: "some_stylesheet.sef.xml",
initialTemplate: "some_template",
sourceLocation: "data:text/xml," + `<some xml/>`,
destination: "application"
};
SaxonJS.transform(options, function(transformResult) {
window.result = transformResult;
window.context = options.context // save first context
console.log(result.textContent);
});
// Modification on SaxonJS.js:
// append line 'options.context = context;' in body of applyStylesheet()
Output
300px
This bin was created anonymously and its free preview time has expired (learn why). — Get a free unrestricted account
Dismiss xKeyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |