diff --git a/exist-app/modules/tapi.xqm b/exist-app/modules/tapi.xqm index 1ebafdb7f36e52f668d6bcb6f86bfc7c03131e3f..836ac8a4092513665c85493e4ae00a51abe05ccb 100644 --- a/exist-app/modules/tapi.xqm +++ b/exist-app/modules/tapi.xqm @@ -247,12 +247,19 @@ as element(object) { :) declare function tapi:make-editors($documentNode as document-node()) as element(x-editor)* { let $role := "editor" - for $editor in $documentNode//tei:titleStmt//tei:editor + let $has-editor := exists($documentNode//tei:titleStmt//tei:editor) return - <x-editor> - <role>{$role}</role> - <name>{$editor/string()}</name> - </x-editor> + if ($has-editor) then + for $editor in $documentNode//tei:titleStmt//tei:editor + return + <x-editor> + <role>{$role}</role> + <name>{$editor/string()}</name> + </x-editor> + else + <x-editor> + <name>none</name> + </x-editor> }; (:~ diff --git a/exist-app/tests.xqm b/exist-app/tests.xqm index c3fcea38270df5c51b67ec527993bccbf66a2a2a..ec5e58c6b097d66a209078773d7b8ac5817a1d9c 100644 --- a/exist-app/tests.xqm +++ b/exist-app/tests.xqm @@ -302,6 +302,14 @@ function tests:make-editors() as element()+ { tapi:make-editors($documentNode) }; +declare + %test:assertXPath("$result[local-name(.) = 'x-editor' and name/text() = 'none']") +function tests:make-editors-fail-gracefully() as element()+ { + let $documentNode := doc("/db/test-records/sample-tei.xml") + return + tapi:make-editors($documentNode) +}; + declare %test:assertXPath("$result[local-name(.) = 'x-date'][text() = '18.10.1697']")