Last active
August 29, 2015 13:56
-
-
Save CliffordAnderson/9028439 to your computer and use it in GitHub Desktop.
Sample query for class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "3.0"; | |
declare namespace tei = "http://www.tei-c.org/ns/1.0"; | |
declare namespace mods = "http://www.loc.gov/mods/v3"; | |
declare function local:gather-information($tei as document-node()) as xs:string* { | |
let $fileDesc := $tei/tei:TEI/tei:teiHeader/tei:fileDesc | |
let $title := $fileDesc/tei:titleStmt/tei:title/text() | |
let $name := $fileDesc/tei:titleStmt/tei:author/text() | |
let $language := $fileDesc/tei:sourceDesc/tei:p/string(@xml:lang) | |
let $place := $fileDesc/tei:publicationStmt/tei:pubPlace/text() | |
let $publisher := $fileDesc/tei:publicationStmt/tei:publisher/text() | |
let $dateIssued := $fileDesc/tei:publicationStmt/tei:date/string(@when) | |
let $identifier := $fileDesc/tei:publicationStmt/tei:idno/text() | |
let $abstract := $tei/tei:TEI/tei:text/tei:front/tei:note[@type = "abstract"]/text() | |
return ($title, $name, $language, $place, $publisher, $dateIssued, $abstract, $identifier) | |
}; | |
declare function local:generate-mods($info as xs:string*) as element(mods:mods) { | |
<mods xmlns="http://www.loc.gov/mods/v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-5.xsd"> | |
<titleInfo> | |
<title>{$info[1]}</title> | |
</titleInfo> | |
<name type="personal"> | |
<namePart>{$info[2]}</namePart> | |
</name> | |
<typeOfResource>text</typeOfResource> | |
<language> | |
<languageTerm>{$info[3]}</languageTerm> | |
</language> | |
<originInfo> | |
<place> | |
<placeTerm>{$info[4]}</placeTerm> | |
</place> | |
<publisher>{$info[5]}</publisher> | |
<dateIssued>{$info[6]}</dateIssued> | |
<issuance>single unit</issuance> | |
</originInfo> | |
<abstract>{$info[7]}</abstract> | |
<subject> | |
<topic/> | |
<geographic/> | |
</subject> | |
<identifier>{$info[8]}</identifier> | |
</mods> | |
}; | |
(: query body :) | |
let $doc := fn:doc("/db/test/tei.xml") | |
let $info := local:gather-information($doc) | |
let $mods := local:generate-mods($info) | |
return xmldb:store("/db/test", "mods.xml", $mods) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment