Skip to content

Instantly share code, notes, and snippets.

@kschlottmann
kschlottmann / componentID.xq
Created January 20, 2019 15:11
Extracts all component level id attributes from EAD
<data>
{
for $Record in /ead
where $Record/archdesc/dsc//c[@id]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $componentID := $Record/archdesc/dsc//@id
return
@kschlottmann
kschlottmann / ead_otherlevel.xq
Created January 20, 2019 15:13
Finds all components that have the otherlevel attribute in EAD
<data>
{
for $Record in /ead
where $Record/archdesc/dsc//c[@level="otherlevel"]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $componentID := $Record/archdesc/dsc//c/@otherlevel
return
@kschlottmann
kschlottmann / ead_filewithinfile.xq
Created January 20, 2019 19:32
Finds components with @Level=file that have a component with @Level=file as a child in an EAD (file within file)
<data>
{
for $Record in /ead
where $Record/archdesc/dsc//c[@level="file"][c[@level="file"]]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $filewithinfile := $Record/archdesc/dsc//c[@level="file"][c[@level="file"]]/did/unittitle
return
@kschlottmann
kschlottmann / ead_empty_p.xq
Last active January 20, 2019 19:54
In an EAD file, finds empty p tags (<p/>) in the dsc
<data>
{
for $Record in /ead
where $Record/archdesc/dsc//p[empty, .]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $empty := $Record/archdesc/dsc//p[empty, .]
return
@kschlottmann
kschlottmann / ead_container_box_nonNumber.xq
Created January 22, 2019 16:37
In an EAD file, will pull out container@typebox/Box where the value is non-numberic
<data>
{
for $Record in /ead
where $Record//container[@type='box'][not(matches(., "^[0-9]"))] or $Record//container[@type='Box'][not(matches(., "^[0-9]"))]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $container := $Record/archdesc/dsc//container[(@type="box" or @type="Box")][not(matches(., "^[0-9]"))]
return
@kschlottmann
kschlottmann / ead_containers_nonboxfolder.xq
Last active January 31, 2019 15:59
In an EAD file, return all container tags that are not type=folder or box
<data>
{
for $Record in /ead[archdesc/dsc//container[not (@type="box" or @type="Box" or @type="Folder" or @type="folder")]]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $container := $Record//container[not (@type="box" or @type="Box" or @type="Folder" or @type="folder")]
order by $repo
@kschlottmann
kschlottmann / flipdatenormal.xsl
Created January 30, 2019 23:31
This xsl will take an EAD where the @Normal dates are reversed (e.g. @Normal="1979/1970") and flip the attribute and value.
<?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:ead="urn:isbn:1-931666-22-9"
exclude-result-prefixes="xs "
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
@kschlottmann
kschlottmann / boxfol.xsl
Created January 31, 2019 20:45
This XSLT will take an EAD where <container @type="Box.Fol">3.35</container> and break into two containers.
<?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:ead="urn:isbn:1-931666-22-9"
exclude-result-prefixes="xs "
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
@kschlottmann
kschlottmann / note_odd.xsl
Last active March 29, 2019 18:03
This Gist will take an EAD file with the format dsc//c/note and flip them to //dsc/c/did/odd
<?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:ead="urn:isbn:1-931666-22-9"
exclude-result-prefixes="xs "
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
@kschlottmann
kschlottmann / dao_xlinkTitle.xsl
Created March 5, 2019 20:56
add xlink:title to dao in an EAD file, derived from unittitle above
<?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:ead="urn:isbn:1-931666-22-9"
xmlns:xlink="http://www.w3.org/1999/xlink"
exclude-result-prefixes="xs "
version="2.0">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>