<< Index

JavaScript Calling XQuery

Page | Source
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>   
    <title>XQIB: Sample page</title>
    <meta charset="UTF-8"/>
    <link href="style.css" rel="stylesheet" type="text/css">
    <script type="application/xquery" src="module.xquery"></script>
    <script type="application/xquery">
      module namespace m = "http://www.xqib.org/module";

      declare function m:generateDiv($node as node()+) {
        for $x in $node/text()
        return
          <div>{
            concat('div generated by XQIB with "',
                   $x,
                   '" which was passed from JS')
          }</div>
      };
    </script>
    <script type="text/javascript" >
      handle = function () {
        var output = xqib.call(
          'http://www.xqib.org/module',
          'generateDiv',
          document.getElementsByTagName('h1'))
        for (i=0;i<output.length;i++){
          document.getElementById('output').appendChild(output[i]);
        }
      };
    </script>
  </head>
  <body>
    <h1>Some Text</h1>
    <h1>Some more text</h1>
	<input type="button" value="Test calling XQIB" onclick="handle()" />
    <div id="output" />
  </body>
</html>