Skip to content

Instantly share code, notes, and snippets.

View grtjn's full-sized avatar

Geert grtjn

View GitHub Profile
@grtjn
grtjn / xqy-sample.xqy
Created October 20, 2011 06:45
A small example of XQuery code that searches for books with the string ‘XQuery’ in its title..
xquery version '1.0';
(: A small example of XQuery code that searches for books with the string ‘XQuery’ in its title.. :)
<html>
<body>
<ul>{
(: Search all books :)
for $b in collection('books')/book
@grtjn
grtjn / compare-xsl.xqy
Created October 20, 2011 13:06
A brief comparison between XQuery and XSLT code
(: A brief comparison between XQuery and XSLT code :)
(: For-each in XQuery.. :)
for $b in $books
order by $b/title
return
$b/title
(: For-each in XSLT.. :)
@grtjn
grtjn / sample-ft.xqy
Created October 20, 2011 13:26
A small example of XPath Full Text..
(: A small example of XPath Full Text.. :)
(: Search books of which the title begins with
‘XQuery’ and ‘novelties’ :)
//book[
title contains text 'XQuery' ftand 'novelties'
ordered distance at most 2 words at start
]
@grtjn
grtjn / sample-xquf.xqy
Created October 20, 2011 13:31
A small example of Update Facility..
(: A small example of Update Facility.. :)
(: Add a new book.. :)
insert node
<book><title>XQuery novelties revisited</title></book>
as last into doc('books.xml')/books
@grtjn
grtjn / sample-xqddf.xqy
Created October 20, 2011 13:33
A small example of XQuery Data Definition Facility..
(: A small example of XQuery Data Definition Facility.. :)
(: Declare a ‘users’ collection :)
declare collection users as element()*;
(: Declare an index on top of ‘users’ using @id :)
declare automatically maintained index users-by-id
on nodes xqddf:collection( xs:QName("users") )
by @id as xs:string;
@grtjn
grtjn / sample-pul.xqy
Created October 20, 2011 13:34
Small example of using versioning..
(: Small example of using versioning.. :)
(: Search for older editions of the current book
: of which the price was twice as much.
:)
past::book[(price div 2) ge current()/price]
@grtjn
grtjn / sample-xqsx.xqy
Created October 20, 2011 13:36
A brief exampe of XQuery 3.0 + Scripting Extensions..
(: A brief exampe of XQuery 3.0 + Scripting Extensions.. :)
(: This example was taken from a Twitter application
: written in XQuery!
:)
(: Follow functionality of Twitter :)
declare sequential function twitter:follow-friend()
{
(: Get the id of user to be followed.. :)
@grtjn
grtjn / split.xsl
Created April 18, 2012 07:47
Dividing title and sub-title on colon inside inlines
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="#all">
<!--+
| Output specs
+-->
<xsl:output method="xml" encoding="UTF-8" indent="no" omit-xml-declaration="yes"/>
<xsl:preserve-space elements="*" />
@grtjn
grtjn / nq2xml.xsl
Created June 27, 2012 08:32
Convert a single line of a turtle .nx or .nq file to xml
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:local="local" xmlns:xdmp="http://marklogic.com/xdmp">
<xsl:variable name="quot">&quot;</xsl:variable>
<xsl:variable name="encoded-string-pattern">^"(([^\\"]+|\\[\\"nrt]|\\u[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]|\\U[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])+)"(.*)</xsl:variable>
<xsl:template match="/">
<!-- http://dbpedia.org/Downloads37 -->
<!-- example input:
@grtjn
grtjn / nx.ebnf
Created June 27, 2012 10:14
Bottlecap Rex EBNF for .nx files
ntripleDoc ::= (line eoln?)* EOF
line ::= comment | triple
triple ::= subject predicate object context? '.'
subject ::= uriref | nodeID
predicate ::= uriref