Skip to content

Instantly share code, notes, and snippets.

@sterkenburgsara-zz
Last active September 25, 2015 21:42
Show Gist options
  • Save sterkenburgsara-zz/94a7502a2052921076bf to your computer and use it in GitHub Desktop.
Save sterkenburgsara-zz/94a7502a2052921076bf to your computer and use it in GitHub Desktop.
xquery version "3.1";
declare namespace tei="http://www.tei-c.org/ns/1.0";
let $doc := fn:doc(
"draft-data-works/251.xml"
)
for $element in $doc//tei:bibl/tei:bibl
where $element/@xml:id
(:let $attribute := $element/@xml:id:)
(:where $element[@xml:id="bibl251-11"]:)
(:let $term := $doc//tei:bibl[@xml:id="bibl251-9"]/text() :)
let $term := $element/text()
let $search-term := fn:substring-after(
$term, "."
)
let $final-search-term := fn:encode-for-uri(
fn:normalize-space(
$search-term
)
)
let $query := fetch:text(
("
http://www.worldcat.org/webservices/catalog/search/opensearch?q="||$final-search-term||"&wskey=[insert-key]"))
let $ref := fn:doc($query)//*:entry[1]/*:id/text()
return if (not(empty ($ref)))then (insert node attribute ref {$ref} into $term)
else ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment