eeditiones / tei-publisher-app

The main TEI Publisher app
https://teipublisher.com
GNU General Public License v3.0
68 stars 33 forks source link

Simplify the raipi:prepare-record function in the registers.xqm module #225

Open daliboris opened 7 months ago

daliboris commented 7 months ago

The raipi:prepare-record function contains typeswitch with identical code in two case clauses, maybe we can simplify it:

let $elements-to-change := ("person", "place") 
(: note:  read names from the configuration, perhaps $config:register-map? :)

let $element-name := if($node instance of element()) then local-name($node) else ()

return if($element-name = $elements-to-change) then
    element {node-name($node)} {
                (: copy attributes :)
                for $att in $node/@* except ($node/@xml:id, $node/@resp, $node/@when)
                return
                    $att
                ,
                attribute xml:id {$id}
                ,
                attribute when {format-date(current-date(), '[Y]-[M,2]-[D,2]')}
                ,
                attribute resp {$resp}
                ,
                for $child in $node/node()
                return $child
            }
    else
        $node

Or you can keep typeswitch expression and modify case clauses like this (see here):

case element(tei:person) | element(tei:place)