transform2teisimple.xqm 2.52 KB
Newer Older
MRodz's avatar
MRodz committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
xquery version "3.1";

(:~ 
 : This modules handles the conversion of the Fontante-TEI/XML into TEISimple
 : for the edited text. The resulting TEISimple is the basis for the "Editerter
 : Text" view on the website and the book.
 : 
 : The resulting TEISimple orientates itself toward the so-called "SUB-Schema"
 : which is a subset for TEISimple that is recommended for future projects that
 : are held by the Göttingen State and University Library (SUB).
 : 
 : @author Michelle Rodzis
 : @version 0.1
 :)

module namespace fontane-simple="http://fontane-nb.dariah.eu/teisimple";

declare namespace tei="http://www.tei-c.org/ns/1.0";
declare namespace test="http://exist-db.org/xquery/xqsuite";

import module namespace console="http://exist-db.org/xquery/console";

(:~ 
 : The main function initiates the transformation of a given notebook.
 : 
 : TODO: adapt to several input files?
 : 
 : :)
declare function fontane-simple:main($file as xs:string) as element(tei:TEI) {
  let $doc := 
    try {
      (doc("/db/sade-projects/textgrid/data/xml/data/" || $file))
    } catch * {
      (console:log("It was not possible to open the requested file " || $file))
    }
    
MRodz's avatar
MRodz committed
37
38
39
40
41
42
43
    let $front-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "front_cover")]/*
    let $back-covers := $doc//tei:sourceDoc/tei:surface[contains(@n, "back_cover")]/*
    let $content := $doc//tei:sourceDoc/tei:surface[not(contains(@n, "cover") 
        and matches(@n, "spine"))]
    
    return 
    <TEI xmlns="http://www.tei-c.org/ns/1.0">
MRodz's avatar
MRodz committed
44
        {$doc//tei:teiHeader}
MRodz's avatar
MRodz committed
45
46
47
48
49
        <text>
            <front>{fontane-simple:transform($front-covers)}</front>
            <body>{fontane-simple:transform($content)}</body>
            <back>{fontane-simple:transform($back-covers)}</back>
        </text>
MRodz's avatar
MRodz committed
50
51
52
53
      </TEI>
};


MRodz's avatar
MRodz committed
54
declare function fontane-simple:transform($nodes as node()*) as item()* {
MRodz's avatar
MRodz committed
55
56
57
58
59
60
61
    for $node in $nodes
      return
        typeswitch ($node)
        case text()
          return
            $node
        case element(tei:surface)
MRodz's avatar
MRodz committed
62
63
64
65
66
67
68
69
70
71
72
73
            return 
                if($node/@type = "label" and
                    (contains($node/@subtype, "Fontane")
                    or contains($node/@subtype, "Hersteller"))    
                )
                    then
                        element{"tei:div"}{
                            attribute{"type"}{"label"},
                            fontane-simple:transform($node/node())
                        }
                    else
                        ()
MRodz's avatar
MRodz committed
74
        default return
MRodz's avatar
MRodz committed
75
          fontane-simple:transform($node/node())
MRodz's avatar
MRodz committed
76
};