Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<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 x
public
Bin info
anonymouspro
0viewers