Skip to content

Instantly share code, notes, and snippets.

View gimsieke's full-sized avatar

Gerrit Imsieke gimsieke

View GitHub Profile
@gimsieke
gimsieke / invocation.sh
Created September 18, 2022 16:28
REx EBNF for a parsing problem presented by Martynas Jusevičius on the xml.com slack
# Go to https://bottlecaps.de/rex/ and use this command line on nested-parentheses.ebnf: -xslt -main -tree -ll 3 -backtrack
# Assumption: A Saxon front-end script called 'saxon' is on the path
saxon -o:out.xml -it:main -xsl:nested-parentheses.xslt input='{(((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))}' '!indent=yes'
# Looking at the main template of the generated XSLT, you need to surround the input string with curly braces; otherweise it will be interpreted as a file name
@gimsieke
gimsieke / in.xml
Created February 1, 2022 21:35
JATS page numbers
<body>
<sec>
<title><target id="p-3"/>Title<fn>
<p>Footnote, <target id="fnp-4"/>continued</p>
</fn></title>
<p>Text<fn>
<p>Second footnote</p>
</fn>
<target id="p-4"/>flow<fn>
<p>Next footnote</p>
@gimsieke
gimsieke / non-tunnel-params.xq
Last active August 20, 2020 18:16
XQuery to report matching XSLT templates with non-tunnel parameters
(: This will report matching XSLT templates with non-tunnel parameters.
These are dangerous because if a template with higher priority or import
precedence intercepts a given template with such a parameter, and then
uses <xsl:next-match/> without passing the parameter, the template will
not receive the same parameter any more. This might not flag an error,
for example if the parameter is declared xs:boolean? or if there is no
as attribute at all. This can lead to unexpected behavior.
Paste the code in in the oXygen XPath/XQuery Builder or execute it
standalone with XQuery-enabled Saxon, and adapt $dir-uri according
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:split="http://www.le-tex.de/XSLT/split"
exclude-result-prefixes="xs split"
version="3.0">
<xsl:mode name="preprocess" on-no-match="shallow-copy"/>
<xsl:mode name="main" on-no-match="shallow-copy"/>
<xsl:mode name="postprocess" on-no-match="shallow-copy"/>
@gimsieke
gimsieke / input.xml
Created May 3, 2020 13:42
XSLT problem raised by Michael Müller-Hillebrand on Mulberry’s xsl-list on 2020-05-03
<?xml version="1.0" encoding="UTF-8"?>
<div>
<h2 id="E2">Item with content to be joined follows div to collect</h2>
<div>
<ol data-meta="listlevel=start">
<li>
<p>1st item</p>
</li>
</ol>
<div class="box" data-meta="collect">
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step
xmlns:p="http://www.w3.org/ns/xproc"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:err="http://www.w3.org/ns/xproc-error"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="urify-test"
version="3.0"
exclude-inline-prefixes="#all">
<p:input port="source" primary="true">
@gimsieke
gimsieke / split.xsl
Created November 24, 2019 17:10
solution for a splitting problem raised by Rick Quatro on Mulberry XSL list on 2019-11-24
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:split="http://www.le-tex.de/XSLT/split"
exclude-result-prefixes="xs" version="3.0">
<!-- invoke it with -lib:lib/split.xsl if you checked out
https://subversion.le-tex.de/common/presentations/2019-02-09_xmlprague_xslt-upward-projection/lib/
to lib/ and if you are using Saxon 9.8+ -->
<xsl:use-package name="http://www.le-tex.de/XSLT/split"
<?xml version="1.0" encoding="utf-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/ns/xproc-step" xmlns:cx="http://xmlcalabash.com/ns/extensions"
xmlns:dc="http://www.delightfulcomputing.com/ns/" version="1.0" name="textdiff-with-options" type="dc:textdiff-with-options">
<p:documentation/>
<p:option name="whitespace" select="'observe'">
<p:documentation>Alternatives: ignore, normalize. Whether inline whitespace is ignored or contracted to a single space
before comparison.</p:documentation>
</p:option>
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:c="http://www.w3.org/ns/xproc-step"
version="1.0"
name="test-params">
<p:input port="params" kind="parameter" primary="true"/>
@gimsieke
gimsieke / ndw50.xpl
Last active June 19, 2017 04:50
a birthday serenade for Norm
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc"
xmlns:ndw50="urn:ndw:birthday:50"
xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:cx="http://xmlcalabash.com/ns/extensions"
version="1.0"
exclude-inline-prefixes="c cx ndw50"
type="ndw50:serenade" name="serenade">
<p:output port="serenade-lines" sequence="true">