Skip to content

Commit f41e2c5

Browse files
committed
refactor links to XSLT
1 parent 57ed149 commit f41e2c5

File tree

6 files changed

+33
-13
lines changed

6 files changed

+33
-13
lines changed

repo/backend/db_switch_build.xqm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ declare namespace dct = "http://purl.org/dc/terms/";
2525
: Creates or updates the two XML documents in the "dots" database.
2626
: @return The two documents to be added to the "dots" database.
2727
:)
28-
declare updating function dots.build:dots_db($rootId := "", $rootTitle := "", $rootDescription := "") {
28+
declare updating function dots.build:dots_db($rootId := "", $rootTitle := "", $rootDescription := "", $linkXSL := "", $defaultEngine := "") {
2929
let $dbSwitch := dots.build:switcher()
30-
let $metadataMap := dots.build:metadataMap($rootId, $rootTitle, $rootDescription)
30+
let $metadataMap := dots.build:metadataMap($rootId, $rootTitle, $rootDescription, $linkXSL, $defaultEngine)
3131
return db:create($G:dots, ($dbSwitch, $metadataMap), ($G:dbSwitcher, $G:metadataMapping))
3232
};
3333

@@ -59,7 +59,7 @@ declare %private function dots.build:switcher() {
5959
: Creates the "dots_default_metadata_mapping.xml" document.
6060
: @return a <metadataMap/> element with XPath-based mappings for title, creator, and publisher metadata.
6161
:)
62-
declare %private function dots.build:metadataMap($rootId as xs:string := "", $rootTitle as xs:string := "", $rootDescription as xs:string := "") {
62+
declare %private function dots.build:metadataMap($rootId as xs:string := "", $rootTitle as xs:string := "", $rootDescription as xs:string := "", $linkXSL as xs:string := "", $defaultEngine as xs:string := "") {
6363
<metadataMap xmlns="https://github.com/chartes/dots/" xmlns:dc="http://purl.org/dc/elements/1.1/"
6464
xmlns:dct="http://purl.org/dc/terms/">{
6565
dots.build:headers("metadataMap"),
@@ -72,6 +72,10 @@ declare %private function dots.build:metadataMap($rootId as xs:string := "", $ro
7272
<dc:title xpath="//titleStmt/title[@type = 'main' or position() = 1]" scope="document"/>
7373
<dc:creator xpath="//titleStmt/author" scope="document"/>
7474
<dct:publisher xpath="//publicationStmt/publisher" scope="document"/>
75-
</mapping>
75+
</mapping>,
76+
<settings>
77+
<linkXSL>{$linkXSL}</linkXSL>
78+
<defaultEngine>{$defaultEngine}</defaultEngine>
79+
</settings>
7680
}</metadataMap>
7781
};

repo/globals.xqm

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,23 @@ declare default element namespace "https://github.com/chartes/dots/";
1515
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ :)
1616

1717
(:~ Variable pour accéder aux feuilles de transformation XSLT :)
18-
(: "../../../../../../../transform/" :)
19-
declare function G:linkToXsl($dbName as xs:string) {
20-
let $specificLink := db:get($dbName, $G:metadata)//settings/linkXSL
18+
(: "/srv/transform/" :)
19+
declare function G:linkToXsl() {
20+
let $specificLink := db:get($G:dots)//settings/linkXSL
2121
return
2222
if ($specificLink)
2323
then if (ends-with($specificLink, "/")) then $specificLink else concat($specificLink, "/")
2424
else concat($G:webapp, "/webapp/static/transform/")
2525
};
2626
(: declare variable $G:xsl := concat($G:webapp, "/webapp/static/transform/"); :)
2727

28-
declare variable $G:defaultXslEnginePath := "Stylesheets/html/html.xsl";
28+
declare function G:defaultXslEnginePath() {
29+
let $defaultEngine := db:get($G:dots)//settings/defaultEngine
30+
where $defaultEngine
31+
return
32+
normalize-space($defaultEngine)
33+
};
34+
(: "hteiml/tei2html.xsl" :)
2935

3036
(: declare variable $G:defaultXslEnginePath := "hteiml/tei2html.xsl"; :)
3137
(: declare variable $G:defaultXslEnginePath := "tei-xsl-7.58.0/xml/tei/stylesheet/txt/tei-to-text.xsl"; :)

scripts/dots_db_init.xq

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ import module namespace script = "script";
77
declare variable $rootId external := ();
88
declare variable $rootTitle external := ();
99
declare variable $rootDescription external := ();
10+
declare variable $linkXSL external := ();
11+
declare variable $defaultEngine external := ();
1012

1113
if (db:exists($G:dots)) then (
1214
script:success("La base de données 'dots' existe déjà. Commande non nécessaire.")
1315
) else (
14-
dots.build:dots_db($rootId, $rootTitle, $rootDescription),
16+
dots.build:dots_db($rootId, $rootTitle, $rootDescription, $linkXSL, $defaultEngine),
1517
script:success("La base de données 'dots' a été initialisée.")
1618
)

scripts/project_create.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ function usage {
3434
echo " (default: false)"
3535
echo " --delete choice to delete only registers or all the database"
3636
echo " (default: false)"
37+
echo " --link_XSL option for the default path to the XSLTs directory"
38+
echo " (default: '') "
39+
echo " --default_engine option for the default Engine XSLT"
40+
echo " (default: '') "
3741
echo " --unit_test choice to launch unit tests"
3842
echo " (default: false)"
3943
echo ""
@@ -58,7 +62,7 @@ elif [[ -z $db_name ]]; then
5862
die "Missing parameter --db_name"
5963
fi
6064

61-
bash "$basex_path/basex" -b rootId=$root_id -b rootTitle="$root_title" -b rootDescription="$root_description" scripts/dots_db_init.xq;
65+
bash "$basex_path/basex" -b rootId=$root_id -b rootTitle="$root_title" -b rootDescription="$root_description" -b linkXSL=$link_XSL -b defaultEngine=$default_engine scripts/dots_db_init.xq;
6266

6367
if [ $cleanOption ]; then
6468
if [ $delete ]; then

scripts/project_create.xq

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ declare variable $option external := ();
99
declare variable $rootId external := ();
1010
declare variable $rootTitle external := ();
1111
declare variable $rootDescription external := ();
12+
declare variable $linkXSL external := ();
13+
declare variable $defaultEngine external := ();
1214

1315
for $script in ('../scripts/dots_db_init.xq', if ($option) then '../scripts/dots_registers_delete.xq', '../scripts/project_db_init.xq',
1416
'../scripts/project_registers_create.xq', '../scripts/TEI_add_id.xq', '../scripts/dots_switcher_update.xq')
@@ -19,6 +21,8 @@ return script:execute(xs:anyURI($script), map {
1921
'option': $option,
2022
'rootId': $rootId,
2123
'rootTitle': $rootTitle,
22-
'rootDescription': $rootDescription
24+
'rootDescription': $rootDescription,
25+
'linkXSL': $linkXSL,
26+
'defaultEngine': $defaultEngine
2327
})
2428

webapp/restxq/routes.xqm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,14 @@ function routes:document(
206206
switch ($media-type)
207207
case ($media-type[. = "html"]) return
208208
let $style :=
209-
let $xsl := G:linkToXsl($dbName)
209+
let $xsl := G:linkToXsl()
210210
return
211211
if (file:exists(concat($xsl, $dbName, "/", $resource, ".xsl")))
212212
then concat($xsl, $dbName, "/", $resource, ".xsl")
213213
else
214214
if (file:exists(concat($xsl, $dbName, "/", $dbName, ".xsl")))
215215
then concat($xsl, $dbName, "/", $dbName, ".xsl")
216-
else concat($xsl, $G:defaultXslEnginePath)
216+
else concat($xsl, G:defaultXslEnginePath())
217217
return
218218
xslt:transform($result, $style)
219219
default return $result

0 commit comments

Comments
 (0)