Skip to content

Commit

Permalink
Fixing: Work title "not found", "fail" etc. (#426)
Browse files Browse the repository at this point in the history
* introducing function for joining strings and normalizing the output

* applying new function

* Update add/data/xqm/util.xqm

Co-authored-by: Peter Stadler <[email protected]>

* removing text selectors, reordering cases and updating xpath

* create 1-arity function

* switch to new function

* fixing typo

* switch to imperative function name

---------

Co-authored-by: Peter Stadler <[email protected]>
  • Loading branch information
riedde and peterstadler authored Oct 11, 2024
1 parent 8742faa commit 49e4764
Showing 1 changed file with 33 additions and 12 deletions.
45 changes: 33 additions & 12 deletions add/data/xqm/util.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ declare function eutil:getLocalizedName($node, $lang) {
if($node/edirom:names) then
($name)
else
($name => string-join(' ') => normalize-space())
(eutil:joinAndNormalize($name))

};

Expand All @@ -107,26 +107,26 @@ declare function eutil:getLocalizedTitle($node as node(), $lang as xs:string?) a
let $namespace := eutil:getNamespace($node)

let $titleMEI :=
if ($lang != '' and $lang = $node/mei:title/@xml:lang and not($node/mei:title/mei:titlePart)) then
($node/mei:title[@xml:lang = $lang]//text() => string-join() => normalize-space())
else if ($lang != '' and $lang = $node/mei:title/@xml:lang and $node/mei:title/mei:titlePart) then
($node/mei:title[@xml:lang = $lang]/mei:titlePart[1]//text() => string-join() => normalize-space())
if ($lang != '' and $lang = $node/mei:title[mei:titlePart]/@xml:lang) then
(eutil:joinAndNormalize($node/mei:title[@xml:lang = $lang]/mei:titlePart, '. '))
else if ($lang != '' and $lang = $node/mei:title[not(mei:titlePart)]/@xml:lang) then
(eutil:joinAndNormalize($node/mei:title[@xml:lang = $lang]))
else
(($node//mei:title)[1]//text() => string-join() => normalize-space())
(eutil:joinAndNormalize(($node//mei:title)[1]))

let $titleTEI :=
if ($lang != '' and $lang = $node/tei:title/@xml:lang) then
$node/tei:title[@xml:lang = $lang]/text()
eutil:joinAndNormalize($node/tei:title[@xml:lang = $lang])
else
$node/tei:title[1]/text()
eutil:joinAndNormalize($node/tei:title[1])

return
if ($namespace = 'mei') then
if ($namespace = 'mei' and $titleMEI != '') then
($titleMEI)
else if ($namespace = 'tei') then
else if ($namespace = 'tei' and $titleTEI != '') then
($titleTEI)
else
('unknown')
('[No title found!]')

};
(:~
Expand Down Expand Up @@ -240,7 +240,7 @@ declare function eutil:getPartLabel($measureOrPerfRes as node(), $type as xs:str
upper-case($i)

return
normalize-space(string-join(($label, $numbering),' '))
eutil:joinAndNormalize(($label, $numbering))

};

Expand Down Expand Up @@ -398,3 +398,24 @@ declare function eutil:request-lang-preferred-iso639() as xs:string {
"en"

};

(:~
: Returns one joined and normalized string
:
: @param $strings The string(s) to be processed
: @return The string (joined with whitespace and normalized space)
:)
declare function eutil:joinAndNormalize($strings as xs:string*) as xs:string {
$strings => string-join(' ') => normalize-space()
};

(:~
: Returns one joined and normalized string
:
: @param $strings The string(s) to be processed
: @param $separator One ore more characters as separators for joining the string
: @return The string (joined and normalized space)
:)
declare function eutil:joinAndNormalize($strings as xs:string*, $separator as xs:string) as xs:string {
$strings => string-join($separator) => normalize-space()
};

0 comments on commit 49e4764

Please sign in to comment.