Skip to content

Instantly share code, notes, and snippets.

@xquery
xquery / gist:350831de91841b84edd9
Created February 13, 2015 16:54
xslt fold example - apply a series of xslt against a single source doc
the following is an example of a left fold xslt
java -jar /Applications/depify-1.0/deps/xmlcalabash/calabash.jar -isource=test.xml -istylesheets=test1.xsl -istylesheets=test2.xsl -oresult=- xslt-fold.xpl
<p:declare-step version="1.0"
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:ex="http://www.example.com"
name="main">
@joewiz
joewiz / payload.xq
Created May 10, 2015 07:23
Receive payloads from BitBucket.org POST hooks with eXist
xquery version "3.1";
(:
Receive payloads from BitBucket.org POST hooks with eXist
Prerequisites:
1. A post-January 2015 build of the develop branch of eXist, which adds support
for XQuery 3.1's JSON parsing and serialization features.
@timathom
timathom / select-all-by-group
Last active August 29, 2015 14:23
XForms select-all-by-group checkboxes in XSLTForms
<?xml-stylesheet type="text/xsl" href="http://localhost:8080/exist/apps/xsltforms/xsltforms.xsl"?><?css-conversion no?><?xsltforms-options debug="yes"?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:bf="http://bibframe.org/vocab/"
xmlns:cwb="http://libserv6.princeton.edu/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<head>
<meta
@jpstroop
jpstroop / sync_exist.sh
Created April 22, 2012 11:57
cron script for keeping eXist in sync with a filesystem
#!/bin/bash
#
# Load incremental changes since the last load. This script maintains a
# hidden file that keeps track of this information.
#
# UTILS
DATE="/bin/date"
CURL="/usr/bin/curl"
@joewiz
joewiz / parse-tweets.xq
Last active October 4, 2015 01:28
Parse and transform tweets using XQuery 3.1's JSON support
xquery version "3.1";
(: parse tweets using XQuery 3.1's JSON support
: see http://www.w3.org/TR/xpath-functions-31/#json
: sample JSON from https://dev.twitter.com/rest/reference/get/statuses/user_timeline
:)
let $json := json-doc('/db/user_timeline.json')
let $tweets := $json?*
return
@joewiz
joewiz / facet-case-1.xq
Last active December 27, 2015 21:09
EXPath Facet Spec workbook
xquery version "3.0";
(:~ An implementation of facet:count as described in "Case 1: Simple facet based on existing attribute"
of the EXPath Facet Spec. Depends on eXist's util:eval() function to handle dynamic path expressions.
@see http://expath.org/spec/facet/20151225#case-1-simple-facet-based-on-existing-attribute
:)
import module namespace util="http://exist-db.org/xquery/util";
@CliffordAnderson
CliffordAnderson / ner.xqy
Last active January 2, 2016 00:39
Named Entity Recognition on Folger's XML Edition of *A Winter's Tale*
xquery version "3.0";
declare namespace tei="http://www.tei-c.org/ns/1.0";
import module namespace ner="http://exist-db.org/xquery/stanford-ner";
let $classifier := xs:anyURI("/db/apps/stanford-ner/resources/classifiers/english.muc.7class.distsim.crf.ser.gz")
for $node in fn:doc("/shakespeare/WT.xml")//tei:ab
let $line :=
<line>{
@timathom
timathom / turtle.xqm
Created February 26, 2016 17:19
XQuery Turtle parser (generated by Gunther Rademacher's REx)
xquery version "1.0" encoding "UTF-8";
(: This file was generated on Sat Feb 13, 2016 20:32 (UTC-05) by REx v5.35 which is Copyright (c) 1979-2015 by Gunther Rademacher <grd@gmx.net> :)
(: REx command line: turtle.ebnf -faster -xquery -tree :)
(:~
: The parser that was generated for the turtle grammar.
:)
module namespace p="turtle";
declare default function namespace "http://www.w3.org/2005/xpath-functions";
@timathom
timathom / sparql-query.xhtml
Last active March 17, 2016 23:08
XForms submission to request non-XML RDF formats from a SPARQL endpoint (DBpedia)
<?xml-stylesheet href="../build/xsltforms.xsl" type="text/xsl"?><?xsltforms-options debug="no"?><?css-conversion no?><?xml-model href="http://www.oxygenxml.com/1999/xhtml/xhtml-xforms.nvdl" schematypens="http://purl.oclc.org/dsdl/nvdl/ns/structure/1.0"?>
<html
xmlns="http://www.w3.org/1999/xhtml"
xmlns:cwb="http://example.org/cwb/"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
@taoyou
taoyou / facets.xq
Created November 5, 2015 22:56
get facets based on path variable
xquery version "3.1";
declare function local:get_facet ($books as element()*, $path as xs:string ) as element()?
{
<binding>{
for $book in $books
let $fld := $book/*[name()=$path]
group by $f := $fld