Skip to content

Instantly share code, notes, and snippets.

View apb2006's full-sized avatar

Andy Bunce apb2006

  • Quodatum
  • London, UK
View GitHub Profile
(: 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 / 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")
declare variable $src:="C:\Users\andy\git\xqlint\test\index.json";
(: json-doc($src) :)
file:read-text($src)=>json-to-xml()
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"})
@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}`"')
@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 / 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>
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- Force all communication over secure channels. -->
<Set name="handler">
<New id="Handlers" class="org.eclipse.jetty.server.handler.HandlerCollection">
<Set name="handlers">
<Array type="org.eclipse.jetty.server.Handler">
<Item>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="BaseX socket test" />
<meta name="author" content="andy bunce." />
<title>BaseX Socket test v2</title>
</head
<body>
<h1>BaseX Socket test</h1>
xquery version "3.0";
(:
Various Date String Parser
- Parses various flavors of date strings, returns as xs:dateTime or xs:date
- Key functions: dates:parseDateTime() and dates:parseDate()
- adapted to an eXist-compatible module from date-parser.xqy from
http://xqzone.marklogic.com/svn/commons/trunk/dates/date-parser.xqy
- by Joe Wicentowski