Skip to content

Instantly share code, notes, and snippets.

@EdWarga
Created July 14, 2015 01:02
Show Gist options
  • Save EdWarga/0c66dc2b6af450366dc4 to your computer and use it in GitHub Desktop.
Save EdWarga/0c66dc2b6af450366dc4 to your computer and use it in GitHub Desktop.
OAI to CSV script in progress.
(:test record = "oai:dash.harvard.edu:1/11210576":)
xquery version "3.1";
declare namespace xsi = "http://www.w3.org/2001/XMLSchema-instance";
declare namespace oai = "http://www.openarchives.org/OAI/2.0/";
declare namespace oai_dc = "http://www.openarchives.org/OAI/2.0/oai_dc/";
declare namespace qdc = "http://purl.org/dc/terms/";
declare namespace dc = "http://purl.org/dc/elements/1.1/";
let $DB := fn:collection("OAI")
let $head := "RecordIdentifier|Creator|Date|Subject|Type|Department"
return
($head,
let $records := $DB//oai:record
for $individual in $records
(:Record Identifier:)
let $recordIDpath := $individual//oai:identifier/text()
let $recordID :=
if (fn:empty($recordIDpath))
then ("NULL")
else if ((count($recordIDpath)) > 1)
then (fn:string-join(($recordIDpath), "; "))
else ($recordIDpath)
(:Creator:)
let $creatorPath := $individual//dc:creator/text()
let $creator :=
if (fn:empty($creatorPath))
then ("NULL")
else if ((count($creatorPath)) > 1)
then (fn:string-join(($creatorPath), "; "))
else ($creatorPath)
let $line := fn:string-join(($recordID, $creator), '|')
return
$line)
@CliffordAnderson
Copy link

Hmmm. I just tried this code, but did not encounter any problem with line breaks. Have you tried fn:normalize-space?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment