Skip to content

Instantly share code, notes, and snippets.

xquery version "3.0";
for $person in /json/_
let $pm:= $person/names/_/sort_name
let $uri:= $person/uri
let $source:= $person/names/_/source
return
<r>
<u>{data($uri)}</u>
@kschlottmann
kschlottmann / every80th.xsl
Created June 14, 2018 01:04
XSLT to grab every 80th record from an OAI output file
<?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 stylesheet will take the output of an oai feed and select every 80th record -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
import requests, csv, json, urllib, time
#to take csv with n columns, and output two columns per row, column 0 and column n
with open('toSplit.txt', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter='|', quotechar='"')
for row in reader:
collection = str(row[0])
#for multiple length csvs, could call len here to define n
n = 1
xquery version "3.0";
declare namespace marc="http://www.loc.gov/MARC21/slim";
(: This xquery will pull all language information from the raw ArchivesSpace MARC output from the OAI feed :)
<results>
{
for $MarcRecord in /repository/record/metadata/marc:collection/marc:record
let $rec := $MarcRecord
xquery version "3.0";
for $resource in /json/_
(: let $label := $resource/notes/_/label[contains(., 'Summary')]
let $type := $resource/notes/_/type[contains(., 'scopecontent')] :)
(: let $label := $resource/notes/_/label[contains(., 'Scope')]:)
let $type := $resource/notes/_/type[../label[contains(., 'Scope') or contains(., 'Summary')]]
@kschlottmann
kschlottmann / ead2csv.xsl
Last active April 12, 2021 12:59
EAD: dsc to csv //edited to move columns around, add physdesc
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" 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">
<xsl:strip-space elements="ead:*" />
<xsl:output method="text" indent="no" encoding="utf-8" standalone="yes"/>
<xsl:variable name="delimiter" select="'|'" />
<xsl:variable name="quote" select="'&quot;'" />
<xsl:variable name="eol" select="'&#10;'" />
<xsl:variable name="startlevel" select="1" />
<xsl:variable name="collprefix" select="lower-case(substring-before(ead:ead/ead:archdesc/ead:did/ead:unitid, '.'))" />
@kschlottmann
kschlottmann / as_ids_from_ead_for_digital_import.xsl
Last active March 30, 2020 14:51
Takes AS ids from an AS-exported EAD and outputs a pipe-separated file compatible with the Harvard Excel DO import plugin
<?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:output omit-xml-declaration="yes"/>
<xsl:template match="ead:ead">
<xsl:for-each select="//ead:c[@level='file']">
<xsl:value-of select="//ead:eadid"/>
@kschlottmann
kschlottmann / maxReaders.py
Created December 1, 2018 16:53
Takes Aeon reader in/out data and caculcates the maximum number of readers
import json
import csv
import os
#function that takes a series of data formatted date, start time, end time and returns max simultaneous calls
def maximumOverlap(calls):
times = []
for call in calls:
date, startTime, endTime = call
@kschlottmann
kschlottmann / ead_empty_unitdate.xq
Last active February 5, 2019 12:45
xquery to find EAD did elements without unittitle or unitdate
<data>
{
for $Record in /ead
where $Record/archdesc/dsc//did/unitdate[not(normalize-space(.))]
let $id := $Record/archdesc/did/unitid[@type='clio']/text()
let $repo := $Record/archdesc/did/unitid[1]/@repositorycode
let $didEmptyTitle := $Record/archdesc/dsc//did/unitdate[not(normalize-space(.))]
return
@kschlottmann
kschlottmann / sort_containers_alpha.xsl
Created January 18, 2019 20:26
Sorts file-level EAD c tags alphabetically.
<?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="c[@level='series']/c[@level='file']">
<xsl:sort select="did/unittitle"/>
<xsl:copy-of select="."/>
</xsl:for-each>