Skip to content

Instantly share code, notes, and snippets.

View grtjn's full-sized avatar

Geert grtjn

View GitHub Profile
@grtjn
grtjn / awesome.xqy
Last active August 29, 2015 14:01
MarkLogic Kick-ass Awesome Thanks..
xquery version "1.0-ml";
declare namespace html = "http://www.w3.org/1999/xhtml";
declare namespace xdmp = "http://marklogic.com/xdmp";
declare function xdmp:tidy-mess($query) {
for $tweet in xdmp:tidy(xdmp:http-get(concat("https://twitter.com/search?q=", encode-for-uri($query)))[2])[2]
//html:div[string(@class) = 'content']
return
<li xmlns="http://www.w3.org/1999/xhtml">{
@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 / 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 / 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-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 / 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 / collector-text.xqy
Created June 27, 2012 10:17
MarkLogic text collector plugin
xquery version "1.0-ml";
(: Copyright 2012 Grtjn. All Rights Reserved. :)
declare namespace textscan = "http://grtjn.nl/marklogic/plugin/textscan";
import module namespace plugin = "http://marklogic.com/extension/plugin" at "/MarkLogic/plugin/plugin.xqy";
import module namespace info="http://marklogic.com/appservices/infostudio" at "/MarkLogic/appservices/infostudio/info.xqy";
import module namespace infodev="http://marklogic.com/appservices/infostudio/dev" at "/MarkLogic/appservices/infostudio/infodev.xqy";