Skip to content

Instantly share code, notes, and snippets.

View apb2006's full-sized avatar

Andy Bunce apb2006

  • Quodatum
  • London, UK
View GitHub Profile
@apb2006
apb2006 / creators.xhtml
Created October 17, 2017 10:49
XForms sample repeating group
<?xml-stylesheet href="../xsltforms/xsltforms.xsl" type="text/xsl"?>
<?css-conversion no?>
<html xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Creator test</title>
<link rel="stylesheet" type="text/css" href="local.css"/>
<xf:model>
@apb2006
apb2006 / json-test.xqm
Created February 25, 2017 17:12
restxq returning json with cors header
(:~
: JSON test apb feb 2017
:)
module namespace page = 'json-test';
(: test data :)
declare variable $page:data:=<json objects="json _">
<total type="number">15</total>
<entity>app</entity>
@apb2006
apb2006 / test.xq
Last active January 5, 2017 20:13
(: queue async run of all tests in $dir :)
declare function local:queue-tests($dir as xs:string,$opts as map(*)) as xs:string
{
let $q:=``[
declare variable $password external;
client:connect('localhost',
db:system()/globaloptions/port/xs:integer(.),
'admin',
$password)
! client:execute(.,'TEST "`{$dir}`"')
import module namespace xp="http://expath.org/ns/xparse";
declare variable $js:="C:\Users\andy\workspace\app-doc\src\static\doc\feats\files\files.js";
let $t:="" || file:read-text($js)
return xp:parse($t,map{"lang":"ecmascript"})
declare variable $src:="C:\Users\andy\git\xqlint\test\index.json";
(: json-doc($src) :)
file:read-text($src)=>json-to-xml()
@apb2006
apb2006 / large-form.xqm
Last active December 6, 2016 12:07
BaseX RESTXQ reading repeated form values
(:~
: JSON form test apb 6dec 2016
:)
module namespace page = 'form-test';
import module namespace request = "http://exquery.org/ns/request";
declare
%rest:path("/form2")
%rest:GET
%output:method("html")
(: https://libertyseeds.ca/2015/07/21/Investigating-Final-Draft-s-XML-document-format-with-Ruby/ :)
declare function local:update($result as map(*),$next as element()) as map(*)
{
let $name:=name($next)
let $current:=$result($name)
let $atribs:=$next/@*[if(empty($current)) then true() else not( .=$current(name(.)))]
let $atribs:=map:merge(($current, $atribs!map:entry(name(.),string(.))), map{'duplicates': 'combine'})
return map:put($result,$name,$atribs)
};
@apb2006
apb2006 / restxq.xqm
Created July 21, 2016 11:47
BaseX RESTXQ Content Negotiation
module namespace page = 'http://basex.org/modules/web-page';
declare
%rest:path("content")
%rest:produces("application/json")
%output:method("json")
function page:content1(){
<json type="object">
<msg>Hello</msg>
</json>
};
@apb2006
apb2006 / rex.xq
Last active May 20, 2016 12:15
call REx from XQuery
(: ebnf to Java parser for BaseX using REx :)
declare function local:REx-request($ebnf as xs:string,$name as xs:string,$command as xs:string)as item()+{
let $req:=
<request xmlns="http://expath.org/ns/http-client" href='http://www.bottlecaps.de/rex/' method="post">
<multipart media-type="multipart/form-data" boundary="xyzBouNDarYxyz">
<header name="Content-Disposition" value='form-data; name="command"'/>
<body media-type="text/plain"/>
<header name="Content-Disposition" value='form-data; name="input"; filename="{$name}.ebnf"'/>
<body media-type="text/plain"/>
</multipart>
@apb2006
apb2006 / trang.xq
Last active April 28, 2016 20:37
Run [Trang](http://www.thaiopensource.com/relaxng/trang.html) from BaseX. Requires trang.jar on path,
declare namespace trang="java:com.thaiopensource.relaxng.translate.Driver";
trang:new()=> trang:run(
("C:\Users\andy\git\qd-cmpx\src\main\content\components.rnc"
,"C:\Users\andy\git\qd-cmpx\src\main\content\output.xsd")
)