Commit c65c389a authored by Wolfgang's avatar Wolfgang

Merge branch 'param-components' into 'master'

allow userParams to be passed to mapping functions

See merge request !72
parents 5bc07442 db7dca6d
......@@ -49,7 +49,7 @@
</body>
</text>
<text type="translation">
<text type="translation" xml:lang="en">
<body>
<div>
<p>T Some text <seg>here</seg> but not necessarily the same deeper structure.</p>
......@@ -81,6 +81,38 @@
</div>
</body>
</text>
<text type="translation" xml:lang="es">
<body>
<div>
<p>T Pretending to be Spanish. Some text <seg>here</seg> but not necessarily the same deeper structure.</p>
<p>T There.</p>
<p>T And elsewhere.</p>
<div>
<p>T Arbitrarily nested.</p>
<p>T And whatnot.</p>
</div>
<div>
<p>T And then some more.</p>
</div>
</div>
<div>
<div>
<p>T Another.</p>
<div>
<p>T Division there.</p>
</div>
<div>
<p>T And elsewhere.</p>
<p>T Foo bar.</p>
<p>T Blah.</p>
</div>
<div>
<p>T Bye bye.</p>
</div>
</div>
</div>
</body>
</text>
</group>
</text>
......
......@@ -93,9 +93,14 @@ let $xml :=
pages:load-xml($view, $root, $doc)
return
if ($xml?data) then
let $userParams :=
map:merge((
request:get-parameter-names()[starts-with(., 'user')] ! map { substring-after(., 'user.'): request:get-parameter(., ()) },
map { "webcomponents": true() }
))
let $mapped :=
if ($mapping) then
let $mapFun := function-lookup(xs:QName("mapping:" || $mapping), 1)
let $mapFun := function-lookup(xs:QName("mapping:" || $mapping), 2)
let $mapped := $mapFun($xml?data)
return
$mapped
......@@ -111,11 +116,7 @@ return
pages:get-content($xml?config, $data)
else
$data
let $userParams :=
map:merge((
request:get-parameter-names()[starts-with(., 'user')] ! map { substring-after(., 'user.'): request:get-parameter(., ()) },
map { "webcomponents": true() }
))
let $html :=
typeswitch ($mapped)
case element() | document-node() return
......@@ -169,7 +170,8 @@ return
<output:indent>no</output:indent>
<output:method>html5</output:method>
</output:serialization-parameters>),
"footnotes": $transformed?footnotes
"footnotes": $transformed?footnotes,
"userParams": $userParams
}
else
map { "error": "Not found" }
......@@ -13,14 +13,14 @@ declare namespace tei="http://www.tei-c.org/ns/1.0";
: For the Van Gogh letters: find the page break in the translation corresponding
: to the one shown in the transcription.
:)
declare function mapping:vg-translation($root as element()) {
declare function mapping:vg-translation($root as element(), $userParams as map(*)) {
let $id := ``[pb-trans-`{$root/@f}`-`{$root/@n}`]``
let $node := root($root)/id($id)
return
$node
};
declare function mapping:cortez-translation($root as element()) {
declare function mapping:cortez-translation($root as element(), $userParams as map(*)) {
let $first := (($root/following-sibling::text()/ancestor::*[@xml:id])[last()], $root/following-sibling::*[@xml:id], ($root/ancestor::*[@xml:id])[last()])[1]
let $last := $root/following::tei:pb[1]
let $firstExcluded := ($last/following-sibling::*[@xml:id], $last/following::*[@xml:id])[1]
......@@ -34,7 +34,7 @@ declare function mapping:cortez-translation($root as element()) {
};
(:~ mapping by retrieving same book number in the translation; assumes div view ~:)
declare function mapping:barum-book($root as element()) {
declare function mapping:barum-book($root as element(), $userParams as map(*)) {
let $bookNumber := $root/@n
let $node := root($root)//tei:text[@type='translation']//tei:div[@type="book"][@n=$bookNumber]
......@@ -42,30 +42,35 @@ declare function mapping:barum-book($root as element()) {
$node
};
(:~ mapping by translating id prefix, by default from prefix s to t1 ~:)
declare function mapping:prefix-translation($root as element(), $userParams as map(*)) {
let $sourcePrefix := ($userParams?sourcePrefix, 's')[1]
let $targetPrefix := ($userParams?targetPrefix, 't1')[1]
let $id := $root/@xml:id
let $node := root($root)/id(translate($id, $sourcePrefix, $targetPrefix))
return
$node
};
(:~ mapping trying to find a node in the same relation to the base of translation as current node to the base of transcription ~:)
declare function mapping:offset-translation($root as element()) {
declare function mapping:offset-translation($root as element(), $userParams as map(*)) {
let $language := ($userParams?language, 'en')[1]
let $node-id := util:node-id($root)
let $source-root := util:node-id(root($root)//tei:text[@type='source']/tei:body)
let $translation-root := util:node-id(root($root)//tei:text[@type='translation']/tei:body)
let $translation-root := util:node-id(root($root)//tei:text[@type='translation'][@xml:lang=$language]/tei:body)
let $offset := substring-after($node-id, $source-root)
let $node := util:node-by-id(root($root), $translation-root || $offset)
let $node := util:node-by-id(root($root), $translation-root || $offset)
return
$node
};
(:~ mapping by translating id prefix ~:)
declare function mapping:prefix-translation($root as element()) {
let $sourcePrefix := 's'
let $translationPrefix := 't1'
let $id := $root/@xml:id
let $node := root($root)/id(translate($id, $sourcePrefix, $targetPrefix))
return
$node
};
......@@ -84,7 +84,12 @@
</section>
<main class="content-body">
<pb-view id="view1" src="document1" xpath="//text[@type='source']/body" column-separator=".tei-cb" append-footnotes="append-footnotes" subscribe="transcription" emit="transcription"/>
<pb-view id="view2" src="document1" map="offset-translation" xpath="//text[@type='source']/body" subscribe="transcription" append-footnotes="append-footnotes"/>
<pb-view id="view2" src="document1" map="offset-translation" xpath="//text[@type='source']/body" subscribe="transcription" append-footnotes="append-footnotes">
<pb-param name="language" value="en"/>
</pb-view>
<pb-view id="view3" src="document1" map="offset-translation" xpath="//text[@type='source']/body" subscribe="transcription" append-footnotes="append-footnotes">
<pb-param name="language" value="es"/>
</pb-view>
</main>
</app-header-layout>
</app-drawer-layout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment