Skip to content

Instantly share code, notes, and snippets.

@joewiz
Created May 31, 2017 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewiz/c4824826092d9be6c73590443ed3a3be to your computer and use it in GitHub Desktop.
Save joewiz/c4824826092d9be6c73590443ed3a3be to your computer and use it in GitHub Desktop.
Sample use of saxon configuration file in oXygen to customize whitespace handling
xquery version "3.0";
(: This query shows how to use the XQuery Update Facility (supported by oXygen's built-in
XQuery processor, Saxon-EE XQuery 9.x).
Run this in oXygen's XQuery Debugger mode, using Window > Open Perspective > XQuery Debugger.
Then select this file from the "XQuery:" toolbar dropdown menu, and click the blue triangle
icon in the toolbar to execute the script. Assuming all goes as planned, you will see a small
window appear, with a yellow triangle icon, saying something like, "The document was modified."
Important notes:
1. do a format & indent on all files before AND after running the XQuery Update
2. use saxon-configuration.xml file (which disables xinclude) and the copy-namespaces
declaration!
Known issues:
1. oxygen still creates backup files even though this is disabled
:)
declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace frus="http://history.state.gov/frus/ns/1.0";
declare copy-namespaces no-preserve, inherit;
let $filenames := ("frus1915Supp.xml", "frus1932v02.xml", "frus1933v04.xml", "frus1934v04.xml", "frus1935v04.xml", "frus1936v01.xml", "frus1936v02.xml", "frus1936v04.xml", "frus1937v01.xml", "frus1938v01.xml", "frus1938v02.xml", "frus1939v02.xml", "frus1941-43.xml", "frus1941v01.xml", "frus1941v03.xml", "frus1941v04.xml", "frus1941v07.xml", "frus1942v06.xml", "frus1943.xml", "frus1943CairoTehran.xml", "frus1943v01.xml", "frus1943v05.xml", "frus1944Quebec.xml", "frus1944v02.xml", "frus1944v03.xml", "frus1944v04.xml", "frus1944v05.xml", "frus1945Berlinv01.xml", "frus1945Berlinv02.xml", "frus1945Malta.xml", "frus1945v02.xml", "frus1945v04.xml", "frus1945v08.xml", "frus1946v01.xml", "frus1946v02.xml", "frus1946v03.xml", "frus1946v04.xml", "frus1946v05.xml", "frus1946v06.xml", "frus1946v07.xml", "frus1946v08.xml", "frus1946v11.xml", "frus1947v01.xml", "frus1947v02.xml", "frus1947v03.xml", "frus1947v04.xml", "frus1947v05.xml", "frus1947v06.xml", "frus1947v08.xml", "frus1948v01p1.xml", "frus1948v01p2.xml", "frus1948v02.xml", "frus1948v03.xml", "frus1948v04.xml", "frus1948v05p1.xml", "frus1948v05p2.xml", "frus1948v06.xml", "frus1948v09.xml", "frus1949v01.xml", "frus1949v02.xml", "frus1949v03.xml", "frus1949v04.xml", "frus1949v05.xml", "frus1949v06.xml", "frus1949v07p1.xml", "frus1949v07p2.xml", "frus1950v01.xml", "frus1950v02.xml", "frus1950v03.xml", "frus1950v04.xml", "frus1950v05.xml", "frus1950v06.xml", "frus1950v07.xml", "frus1951v01.xml", "frus1951v02.xml", "frus1951v03p1.xml", "frus1951v03p2.xml", "frus1951v04p1.xml", "frus1951v04p2.xml", "frus1951v05.xml", "frus1951v06p1.xml", "frus1951v06p2.xml", "frus1951v07p1.xml", "frus1951v07p2.xml", "frus1952-54v03.xml")
let $vols := subsequence($filenames, 81, 40) ! doc('file:/Users/joe/workspace/hsg-project/repos/frus/volumes/' || .)
(:
:)
return element results {
for $vol in $vols
for $opener in $vol//tei:opener[count(tei:dateline) eq 1 and count(tei:seg) gt 1 and tei:seg[last()] << tei:dateline[1] (: and count(./child::element()) gt 2 :) ]
return
element result {
attribute vol { base-uri($opener) },
attribute doc { $opener/ancestor::tei:div[@xml:id][1]/@xml:id },
$opener,
(:
replace node $opener with
:)
element { QName('http://www.tei-c.org/ns/1.0', 'opener') }
{
element { QName('http://www.tei-c.org/ns/1.0', 'seg') } {
attribute rendition { "#left" },
let $segs := $opener/tei:seg
for $seg at $n in $segs
return
if ($n lt count($segs)) then
($seg/node(), element { QName('http://www.tei-c.org/ns/1.0', 'lb') } {()}, " ")
else
$seg/node()
},
" ",
$opener/tei:dateline, " "
}
}
}
(:
:)
<?xml version="1.0" encoding="UTF-8"?>
<configuration edition="EE" xmlns="http://saxon.sf.net/ns/configuration">
<global stripSpace="none" xInclude="false"/>
<xquery allowUpdate="true" version="3.0"/>
</configuration>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment