Skip to content

Commit

Permalink
Add a flag if a TEI XML contains any tei:w
Browse files Browse the repository at this point in the history
There may be metadata TEIs that do not have any token.
Also improve error message for invalid TEI collection types.
  • Loading branch information
simar0at committed Jun 21, 2024
1 parent 6d2c36f commit f2c5abe
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions vicav.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -1769,15 +1769,22 @@ declare function vicav:_get_tei_doc_list($type as xs:string*) {
error(xs:QName('response-codes:_422'),
$api-problem:codes_to_message(422),
'You need to specify a type') else (),
$corpus := collection($type)//tei:teiCorpus,
$corpus := try { collection($type)//tei:teiCorpus } catch err:FODC0002 {
error(xs:QName('response-codes:_404'),
$api-problem:codes_to_message(404),
'There are no TEI documents of type '||$type)},
$corpus := if (not(exists($corpus)) and exists(collection($type)//tei:TEI))
then <teiCorpus xmlns="http://www.tei-c.org/ns/1.0">{collection($type)//tei:TEI!. update {delete node ./tei:text}}</teiCorpus>
else $corpus,
$corpus := if (exists($corpus/@xml:id)) then $corpus else $corpus update { insert node attribute {"id"} {$type} as first into . },
$notFound := if (not(exists($corpus))) then
error(xs:QName('response-codes:_404'),
$api-problem:codes_to_message(404),
'There are no TEI documents of type '||$type) else ()
'There are no TEI documents of type '||$type) else (),
$corpusIDs := $corpus//tei:idno[contains(@type, 'CorpusID')]/text()!xs:string(.),
$IDtypes := distinct-values($corpus//tei:idno/@type),
$IDsContainingData := collection($type)//tei:TEI[.//tei:w]//tei:idno[@type = $IDtypes][. = $corpusIDs]!xs:string(.),
$corpus := $corpus update { .//tei:TEI[.//tei:idno[@type = $IDtypes][. = $IDsContainingData]]!(insert node attribute {"hasTEIw"} {"true"} as first into .) }
return serialize(xslt:transform($corpus, 'xslt/teiCorpusTeiHeader-json.xslt'), map {'method': 'json'})
};

Expand Down

0 comments on commit f2c5abe

Please sign in to comment.