Skip to content

Commit

Permalink
provided support (via URL parameter) for different XML output formats,
Browse files Browse the repository at this point in the history
  • Loading branch information
peterstadler committed Sep 13, 2017
1 parent 6b1d13c commit 452c6fe
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions modules/config.xqm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ declare variable $config:repo-descriptor as element(repo:meta) := doc(concat($co

declare variable $config:valid-resource-suffixes as xs:string* := ('html', 'htm', 'json', 'xml', 'tei');

(: collection that provides XSL scripts for transforming our documents to external schemas, e.g. tei_all :)
declare variable $config:xsl-external-schemas-collection-path as xs:string := $config:app-root || '/resources/lib/WeGA-ODD/xsl';

(: The first language is the default language :)
declare variable $config:valid-languages as xs:string* := ('de', 'en');

Expand Down
18 changes: 17 additions & 1 deletion modules/view-xml.xql
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ import module namespace gl="http://xquery.weber-gesamtausgabe.de/modules/gl" at

declare option exist:serialize "method=xml media-type=application/tei+xml indent=no encoding=utf-8";

declare function local:format() as xs:string? {
let $req-format := request:get-parameter('format', ())
let $supported := local:available-transformations()
return
($req-format[.=$supported])[1]
};

declare function local:available-transformations() as xs:string* {
xmldb:get-child-resources($config:xsl-external-schemas-collection-path) ! (substring-before(substring-after(., 'to-'), '.xsl'))
};

let $docID := request:get-attribute('docID')
let $specID := request:get-attribute('specID')
let $schemaID := request:get-attribute('schemaID')
Expand All @@ -21,7 +32,12 @@ let $content :=
else if($chapID) then gl:chapter($chapID)
else if($dbPath) then try {doc($dbPath)} catch * { core:logToFile('error', 'Failed to load XML document at "' || $dbPath || '"') }
else ()
let $format := local:format()
let $transformed :=
if($format) then wega-util:transform($content, doc($config:xsl-external-schemas-collection-path || '/to-' || $format || '.xsl'), ())
else $content
return
wega-util:inject-version-info(
wega-util:remove-comments($content)
if($config:isDevelopment) then $transformed
else wega-util:remove-comments($transformed)
)

0 comments on commit 452c6fe

Please sign in to comment.