Skip to content
Snippets Groups Projects
ifweb.xql 2.41 KiB
Newer Older
  • Learn to ignore specific revisions
  • (:~ 
     : ifweb.xql offers a simple interface for creating the website specific BdN
     : intermediate format of a given resource.
     : 
     : @author Michelle Rodzis
     : @version 1.0
     : 
     :)
    xquery version "3.1";
    
    module namespace ifweb="http://bdn-edition.de/intermediate_format/ifweb";
    
    declare namespace tei = "http://www.tei-c.org/ns/1.0";
    
    
    MRodz's avatar
    MRodz committed
    import module namespace console="http://exist-db.org/xquery/console";
    
    import module namespace pre="http://bdn-edition.de/intermediate_format/preprocessing" at "xmldb:exist:///db/apps/interformat/modules/intermediate_format/preprocessing.xqm";
    import module namespace ident = "http://bdn-edition.de/intermediate_format/identification" at "xmldb:exist:///db/apps/interformat/modules/intermediate_format/identification.xqm";
    import module namespace config = "http://bdn-edition.de/intermediate_format/config" at "xmldb:exist:///db/apps/interformat/modules/config.xqm";
    
    declare option exist:serialize "method=xml media-type=text/xml omit-xml-declaration=no indent=no";
    
    
    MRodz's avatar
    MRodz committed
    
    
    declare function ifweb:main($resource as xs:string) as xs:string? {
        let $doc := doc($config:sade-data || $resource)
        let $filename := substring-before($resource, '.xml') || "-if.xml"
        
    
    MRodz's avatar
    MRodz committed
        return ifweb:transform($doc, $filename)
    };
    
    
    declare function ifweb:transform($doc as node()*, $filename as xs:string) 
    as node()* {
    
    MRodz's avatar
    MRodz committed
        let $replace-whitespace := true()
    
    MRodz's avatar
    MRodz committed
        let $log := console:log("Start preprocessing.")
    
        let $preprocessed-data := pre:preprocessing($doc/tei:TEI, $replace-whitespace)
    
    MRodz's avatar
    MRodz committed
        let $log := console:log("Start main processing.")
    
        let $intermediate-format := ident:walk($preprocessed-data, ())
    
    MRodz's avatar
    MRodz committed
        let $store := xmldb:store($config:sade-data, $filename, $intermediate-format)
    
    MRodz's avatar
    MRodz committed
        return $intermediate-format
    };
    
    declare function ifweb:complete-xml($author as xs:string, $xml as node()*) 
    as node()* {
    
    MRodz's avatar
    MRodz committed
        let $log-dir :=
            if(xmldb:collection-available($config:app-root || "/logs")) then
                $config:app-root || "/logs" 
            else
                xmldb:create-collection($config:app-root, "logs")
        let $log-name := "log.xml"
        let $create := xmldb:store($log-dir, $log-name, <root/>)
                
    
    MRodz's avatar
    MRodz committed
        let $filename := $author || "-full-if.xml"
        return ifweb:transform($xml, $filename)
    };
    
    declare function ifweb:single-xml($resource as node()*, $filename as xs:string) 
    as node()* {
        let $filename := substring-before($filename, '.xml') || "-if.xml"
        return ifweb:transform($resource, $filename)