Skip to content

Instantly share code, notes, and snippets.

View nine9ths's full-sized avatar

Nick Nunes nine9ths

  • Audible Magic
  • East Bay, CA
View GitHub Profile
@nine9ths
nine9ths / A
Last active August 29, 2015 14:10
Thoughts on XSLT grouping
<!--
From http://www.w3.org/TR/xslt-30/
A standard grouping exercise to wrap a group of elements
-->
<xsl:template match="body">
<chapter>
<xsl:for-each-group select="*" group-starting-with="h2">
<section title="{self::h2}">
<xsl:for-each select="current-group()[self::p]">
<para><xsl:value-of select="."/></para>
@nine9ths
nine9ths / dump.defaults.zsh
Last active January 3, 2016 09:49
Command to dump all OS X defaults to XML plist files
foreach f ('NSGlobalDomain' `defaults domains`)
d=`echo $f | sed 's/,$//'`
defaults export $d $d.plist && plutil -convert xml1 $d.plist
end
@nine9ths
nine9ths / bug.fallback.saxon.xsl
Last active December 31, 2015 01:59
In Saxon-EE 9.5.1.2 there seems to be a problem when evaluating predicates with equality tests from a variable that might be a document-node() which has a fallback instruction.
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ext="http://example.com/extensions"
extension-element-prefixes="ext"
exclude-result-prefixes="xs">
<xsl:template match="/">
<xsl:variable name="test" as="document-node(element(foo))?">
@nine9ths
nine9ths / bug.doc-available.xsl
Last active December 21, 2015 03:59
In Oxygen 16.0, build 2014070913, on OS X 10.9.5, the bundled Saxon 9.5.1.5 is bugged with fn:doc-available(). If the target is an empty file, it returns a parsing error rather than false. The stylsheet below returns the error "Premature end of file."
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template name="main">
<xsl:sequence select="doc-available('empty.xml')"/>
</xsl:template>
</xsl:stylesheet>
@nine9ths
nine9ths / test.apply-imports.imported.xsl
Created June 27, 2013 00:14
Demonstrate differences between xsl:apply-imports and xsl:next-match for controlling import precedence.
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs">
<xsl:template match="foo">
<bar/>
</xsl:template>
let
$isNegative := function($x as xs:integer) {$x lt 0},
$decrement := function($x as xs:integer) {$x - 1},
$until.r :=
function(
$p as function(item()*) as xs:boolean,
$f as function(item()*) as item()*,
$x as item()*,
$r as function(function(), function(), item()*, function()) as item()*) as item()* {
if ($p($x)) then $x else $helper($p, $f, $f($x), $r)
@nine9ths
nine9ths / collapse.caps.3.xpath
Created January 8, 2013 23:18
Replace an uppercase character followed by the lowercase version of itself (e.g. 'Qq') with just the lowercase character in XPath 3.0 with examples in XQuery 3.0 and XSLT 3.0
function($input as xs:string) as xs:string {
fold-left(
function($s,$r){
replace($s,upper-case($r)||$r,$r)
},
$input,
((1 to 26) ! format-integer(.,'a')))
}
@nine9ths
nine9ths / create.catalogfile.saxon.3.xslt
Last active December 10, 2015 07:38
XSLT 3.0 stylesheet for Saxon to create a saxon catalog file for collections
<xsl:stylesheet
version="3.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:file="java:java.io.File"
xmlns:jt="http://saxon.sf.net/java-type"
exclude-result-prefixes="xs file jt">
<xsl:param name="directory"/>