Next in thread →
Next in month →
Re: [xml-dev] [ANN] XQuery in the Browser, JavaScript Edition
As a follow-up, I've been playing with xqib-js on my laptop most of the evening, and my reaction to this has escalated from "cool" to "incredible!" to "this is a frigging game changer!!". I've already started writing an article on it, should have something published over the weekend.
I've just been playing around with it, after installing the archive, and have ended up with a quick "test" script:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XQIB: Sample page</title>
<meta charset="UTF-8"/>
<script type="text/javascript" src="mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="text/xml" src="/lib/resources/colors.xml" id="data"></script>
<script type="text/xquery">
declare variable $foo := "XQuery!";
declare function local:get-color-list($url as xs:string) as node(){
(let $colors := fn:doc($url) return
<div style="background-color:lightGray;">
<h3>Colors</h3>
<ul>{
for $term in $colors//*:term
return
<li style="color:{$term/*:value}">
<span style="color:black">{fn:string($term/*:label)}</span>
</li>
}
</ul></div>)
};
declare updating function local:main() {
let $eltnames := ("h1","h2","h3","h4","h5","h6","fieldset")
let $elts := for $eltname in $eltnames return element {$eltname} {"This is a test. This is only a test."}
let $bar := b:dom()//div[@id='bar']
let $table :=
<table>
<tr>
<th>Element Name</th>
<th>Example Text</th>
</tr>
{for $index in (1 to fn:count($elts))
return <tr>
<td>{$eltnames[$index]}</td>
<td>{$elts[$index]}</td>
</tr>
}
</table>
return (
insert node <div>{$elts}</div> as first into $bar,
insert node $table as last into $bar,
insert node <div>{fn:string-join(fn:tokenize("red,green,blue,yellow",","),";")}</div> as last into $bar,
insert node local:get-color-list("http://localhost:8100/lib/resources/colors.xml") as last into $bar,
insert node <div>{$foo}</div> as last into $bar)
};
</script>
</head>
<body>
<h1>Test Page</h1>
<div id="bar"></div>
<hr></hr>
</body>
</html>
Next in thread →
Next in month →