transform2teisimple.xqm 2.75 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
37
38
39
40
41
42
43
44
45
46
47
48
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))
    }
    let $content := $doc//tei:sourceDoc
    let $transform := fontane-simple:transform($content)
    
    let $tei-simple :=
      <TEI xmlns="http://www.tei-c.org/ns/1.0">
        {$doc//tei:teiHeader}
        {$transform}
      </TEI>
    
    return $tei-simple
};


MRodz's avatar
MRodz committed
49
declare function fontane-simple:transform($nodes as node()*) as item()* {
MRodz's avatar
MRodz committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    for $node in $nodes
      return
        typeswitch ($node)
        case text()
          return
            $node
        case element(tei:sourceDoc) 
          return
            element{"tei:text"}{
              fontane-simple:transform($node/node())
            }
        case element(tei:surface)
          return
            (: book covers :)
            if(contains($node/@n, "cover")
            and 
              (: all covers with a label ... :)
              (contains($node/tei:surface/@subtype, "Fontane")
              or contains($node/tei:surface/@subtype, "Hersteller")
              (: or text directly written on it :)
              or not($node/tei:surface))
            ) 
              then
              element{"tei:front"}{
                fontane-simple:transform($node/node())
              }
            (: labels on book covers and spine :)
            else 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
              ()
        default return
          ()
};