Skip to content

Instantly share code, notes, and snippets.

@CJHArch
CJHArch / daosFromEad
Created July 19, 2016 20:20
This will pull the identifiers and partners from EADs containing a dao (i.e. allowing a count of finding aids that link to digital material)
<data>
{
for $Record in /ead[archdesc/dsc/descendant::dao]
let $id := $Record/archdesc/did/unitid
let $repo := $Record/archdesc/did/repository
let $address := $Record/eadheader/filedesc/publicationstmt/address/addressline[1]
return
@CJHArch
CJHArch / foldersPhotos.xsl
Last active May 4, 2016 17:54
Add sequential numbers to EAD folder titles. Each folder needed a consecutive number. Its xpath position matched the actual position in the finding aid.
<?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"
exclude-result-prefixes="xs"
version="2.0">
<!--copy everything-->
<!-- KS 20150831 This stylesheet takes the output from the Excel-to-DSC_CJH xsl and moves up the container to before the did -->
@CJHArch
CJHArch / LBI_655s
Last active January 20, 2016 17:48
This xquery pulls out 655s from the namespace-stripped Digitool OAI feed, as well as limiting by 852 and pulling out 852 information. Together with an XSLT that grouped the 665s into one tag, and an Excel text-to-columns conversion, we got the data.
xquery version "3.0";
<results>
{
for $OAIMarcRecord in /repository/record[metadata/record/datafield[@tag="852"][contains(., "Baeck")]]
let $callno:= $OAIMarcRecord/metadata/record/datafield[@tag="094"]
let $title := $OAIMarcRecord/metadata/record/datafield[@tag="245"]
let $eighta := $OAIMarcRecord/metadata/record/datafield[@tag="852"]/subfield[@code='a']
let $eightb := $OAIMarcRecord/metadata/record/datafield[@tag="852"]/subfield[@code='b']
@CJHArch
CJHArch / filesize from digital entity
Created January 4, 2016 18:17
This will sum the file size data from a group of Digitool digital entity XML files (name space stripped)
xquery version "3.0";
sum
(
for $de in /digital_entity_call/digital_entity/stream_ref/file_size_bytes
return $de
)
<?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" exclude-result-prefixes="xs" version="2.0">
<!-- This template will take hyphen in the unittitle EAD tag and, in cases where it is between a lower-case letter and an upper-case letter, replace it within an em-dash -->
<!-- For example: <unittitle>Correspondence-Wax</unittitle> to <unittitle>Correspondence—Wax</unittitle> -->
<!-- Be sure to use an XSLT 2.0 engine -->
<xsl:template match="@*|node()">
<xsl:copy>
@CJHArch
CJHArch / dtl_md_index
Created October 23, 2015 13:32
XSLT to create csv of all metadata field indexed by Digitool, extracted from the repository_indexing_schema.xml file. NB I removed the namespace from the xml file first.
<?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"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:for-each select="silo_schema/fields/field[location/@type='digital_entity']">
<xsl:value-of select="@ui_default_text"/>
<xsl:text>,</xsl:text>
@CJHArch
CJHArch / add_level.xsl
Created October 8, 2015 14:36
This XSLT adds a level attribute to the c03 components lacking one, in an EAD stylesheet
<?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"
exclude-result-prefixes="xs"
version="2.0">
<!-- IdentityTransform -->
<xsl:template match="/ | @* | node()">
@CJHArch
CJHArch / gist:9378aef7244cdd0301b6
Created September 2, 2015 14:02
XSL to insert blank <container> into EAD (to address the c03 c04 repitition issue)
<?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"
exclude-result-prefixes="xs"
version="2.0">
<!--copy everything-->
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="@* | node()">
<xsl:copy>
@CJHArch
CJHArch / gist:c20d57be953e78cadfc3
Created August 25, 2015 19:03
TSV out of EAD
<?xml version="1.0" encoding="UTF-8"?>
<!-- This stylesheet will generate a tsv file from an EAD container list. It will catch all c0X elements that have a did/container child -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- We don't want an xml declaration in the output, since this will just be a tab-separated text file-->
<xsl:output omit-xml-declaration="yes"/>
<!-- We don't want extra space floating around -->
@CJHArch
CJHArch / .xq
Created July 28, 2015 18:52
dtl_oai_languages
xquery version "3.0";
<results>
{
for $OAIMarcRecord in /repository/record
where $OAIMarcRecord/metadata/record/datafield[@tag="041"] or $OAIMarcRecord/metadata/record/datafield[@tag="546"] or $OAIMarcRecord/metadata/record/controlfield[@tag="008"]
let $callno:= $OAIMarcRecord/metadata/record/datafield[@tag[contains(., "09")]][1]/subfield[@code="a"]
let $title := $OAIMarcRecord/metadata/record/datafield[@tag="245"]