Skip to content

Commit

Permalink
Merge pull request #165 from Edirom/issue-164
Browse files Browse the repository at this point in the history
dynamically set the MerMEId version
  • Loading branch information
peterstadler authored May 26, 2023
2 parents 210b08a + d7e614c commit 7fcb7d7
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion data/controller.xql
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ else if($exist:path = '/create' and request:get-method() eq 'POST') then
let $change-message := 'file created with MerMEId'
let $template :=
if(doc-available($templatepath))
then doc($templatepath) => common:set-mei-title-in-memory($title) => common:add-change-entry-to-revisionDesc-in-memory($username, $change-message)
then doc($templatepath) =>
common:set-mei-title-in-memory($title) =>
common:add-change-entry-to-revisionDesc-in-memory($username, $change-message) =>
common:set-mermeid-version-info-in-memory()
else ()
let $filename := request:get-parameter('filename', common:mermeid-id('file') || '.xml')
let $overwrite := local:overwrite()
Expand Down
32 changes: 32 additions & 0 deletions modules/common.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,35 @@ declare function common:set-mei-title-in-memory($nodes as node()*, $new_title as
declare function common:get-current-username() as xs:string? {
sm:id()//sm:real/sm:username => data()
};

(:~
: Set/Update the MerMEId version within an MEI document in memory.
: NB, this will _not_ modify any existing document in the database!
:
: @param $node the input MEI document as node() or document-node()
: @param $new_title the new title
: @return the modified input node
:)
declare function common:set-mermeid-version-info-in-memory($nodes as node()*) as node()* {
for $node in $nodes
return
typeswitch($node)
case $elem as element(mei:application) return
if($elem/mei:name ='MerMEId')
then
element { node-name($elem) } {
attribute version {$config:version},
$elem/@* except $elem/@version,
for $child in $elem/node() return common:set-mermeid-version-info-in-memory($child)
}
else
element { node-name($elem) } {
$elem/@*, for $child in $elem/node() return common:set-mermeid-version-info-in-memory($child)
}
case $elem as element() return
element { node-name($elem) } {
$elem/@*, for $child in $elem/node() return common:set-mermeid-version-info-in-memory($child)
}
case document-node() return document { common:set-mermeid-version-info-in-memory($node/node()) }
default return $node
};

0 comments on commit 7fcb7d7

Please sign in to comment.