-
Notifications
You must be signed in to change notification settings - Fork 4
/
testimony.xpl
219 lines (180 loc) · 9.93 KB
/
testimony.xpl
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
49
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?xml version="1.0" encoding="UTF-8"?>
<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" xmlns:c="http://www.w3.org/ns/xproc-step"
xmlns:cx="http://xmlcalabash.com/ns/extensions" xmlns:f="http://www.faustedition.net/ns"
xmlns:t="http://www.faustedition.net/ns/testimony"
xmlns:pxf="http://exproc.org/proposed/steps/file"
xmlns:l="http://xproc.org/library" type="f:testimony" name="main" version="1.0">
<p:input port="source"><p:empty/></p:input>
<p:input port="parameters" kind="parameter"/>
<p:output port="result" primary="true"/>
<p:option name="paths" select="'paths.xml'"/>
<p:import href="library/recursive-directory-list.xpl"/>
<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/>
<!-- Konfiguration laden -->
<p:xslt name="config" template-name="param">
<p:input port="source"><p:empty/></p:input>
<p:input port="stylesheet"><p:document href="xslt/config.xsl"/></p:input>
<p:with-param name="path_config" select="$paths"></p:with-param>
</p:xslt>
<p:group>
<p:variable name="source" select="//c:param[@name='source']/@value"><p:pipe port="result" step="config"/></p:variable>
<p:variable name="debug" select="//c:param[@name='debug']/@value"><p:pipe port="result" step="config"/></p:variable>
<p:variable name="builddir" select="resolve-uri(//c:param[@name='builddir']/@value)"><p:pipe port="result" step="config"/></p:variable>
<p:variable name="testihtml" select="concat($builddir, 'www/testimony/')"><p:pipe port="result" step="config"></p:pipe></p:variable>
<cx:message log="info">
<p:input port="source"><p:pipe port="source" step="main"></p:pipe></p:input>
<p:with-option name="message" select="concat('Collecting testimony from ', $source)"/>
</cx:message>
<!-- Recursively list all files in testimony/**/*.xml -->
<l:recursive-directory-list name="ls">
<p:with-option name="path" select="concat($source, '/testimony')"/>
<p:with-option name="include-filter" select="'^\w\S+$'"/>
<p:with-option name="exclude-filter" select="'.*\.html$'"></p:with-option>
</l:recursive-directory-list>
<!-- Convert each file to HTML -->
<p:for-each name="convert-testimonies">
<p:iteration-source select="//c:file[$debug or not(ends-with(@name, 'test.xml'))]"/>
<p:variable name="filename" select="p:resolve-uri(/c:file/@name)"/>
<p:variable name="basename" select="replace(replace($filename, '.*/', ''), '.xml$', '')"/>
<p:variable name="outfile" select="p:resolve-uri(concat($basename, '.html'), $testihtml)"/>
<p:load name="load-testimony">
<p:with-option name="href" select="$filename"/>
</p:load>
<p:xslt name="normalize-footnotes">
<p:with-option name="output-base-uri" select="p:base-uri()"/>
<p:input port="stylesheet"><p:document href="xslt/normalize-footnotes.xsl"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
</p:xslt>
<p:xslt name="testimony-xml">
<p:with-option name="output-base-uri" select="p:base-uri()"/>
<p:input port="stylesheet"><p:document href="xslt/normalize-characters.xsl"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
</p:xslt>
<p:xslt name="split-testimony">
<p:with-option name="output-base-uri" select="p:base-uri()"/>
<p:input port="stylesheet"><p:document href="xslt/testimony-split.xsl"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:with-param name="builddir-resolved" select="$builddir"/>
<p:with-param name="source-uri" select="$filename"/>
</p:xslt>
<p:sink/>
<p:for-each>
<p:iteration-source>
<p:pipe port="secondary" step="split-testimony"/>
</p:iteration-source>
<p:variable name="base-uri" select="p:base-uri()"/>
<p:variable name="html-file" select="p:resolve-uri(replace(p:base-uri(), '.*/([^/.]*)\.xml$', '$1.html'), $testihtml)"/>
<p:identity name="single-testimony-tei"/>
<p:store indent="false">
<p:with-option name="href" select="p:base-uri()"/>
</p:store>
<p:xslt name="do-single-testimony-tei">
<p:input port="source"><p:pipe port="result" step="single-testimony-tei"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:input port="stylesheet"><p:document href="xslt/single-testimony-html.xsl"/></p:input>
<p:with-param name="builddir-resolved" select="$builddir"></p:with-param>
</p:xslt>
<p:store encoding="utf-8" method="xhtml" include-content-type="false" indent="true">
<p:with-option name="href" select="$html-file"/>
</p:store>
<!-- For search, we skip the context data -->
<p:xslt>
<p:input port="source"><p:pipe port="result" step="single-testimony-tei"/></p:input>
<p:input port="stylesheet">
<p:inline>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="http://www.tei-c.org/ns/1.0">
<xsl:import href="xslt/testimony-common.xsl"/>
<xsl:template match="t:field">
<xsl:variable name="spec" select="f:fieldspec(@name)"/>
<xsl:choose>
<xsl:when test="$spec/@ignore='yes'"/>
<xsl:otherwise>
<xsl:copy copy-namespaces="no">
<xsl:attribute name="label" select="if ($spec/text()) then $spec/text() else $spec/@spreadsheet"/>
<xsl:apply-templates select="@* except @label, node()"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/TEI/text">
<xsl:apply-templates select="group/text[@copyOf]"/>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="@*, node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
</p:inline>
</p:input>
<p:input port="parameters"><p:empty/></p:input>
</p:xslt>
<p:store encoding="utf-8" method="xml" include-content-type="false" indent="false">
<p:with-option name="href" select="p:resolve-uri(replace($base-uri, '.*/([^/.]*)\.xml$', '$1.xml'), concat($builddir, '/search/testimony/'))"/>
</p:store>
<!-- Now, the file we've just converted is read again and we collect all the <milestone unit='testimony' xml:id='two_part_id' -->
<p:xslt name="testimony-get-citations">
<p:input port="source"><p:pipe port="result" step="single-testimony-tei"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:with-param name="from" select="replace($filename, concat('^', $source), 'faust://xml/')"/>
<p:with-param name="outfile" select="$outfile"/>
<p:with-param name="builddir-resolved" select="$builddir"></p:with-param>
<p:with-option name="template-name" select="'get-citations'"></p:with-option>
<p:input port="stylesheet"><p:document href="xslt/testimony2html.xsl"/></p:input>
</p:xslt>
</p:for-each>
<p:wrap-sequence wrapper="f:citations" name="citations-by-source"/>
</p:for-each>
<!-- Now we've an index doc for every testimony file, join them together -->
<p:identity name="testimony-index-parts"/>
<p:wrap-sequence wrapper="f:testimony-index" name="wrapped-testis">
<p:input port="source">
<p:pipe port="result" step="testimony-index-parts"/>
</p:input>
</p:wrap-sequence>
<p:unwrap match="f:citations" name="testimony-index"/>
<!-- We save this for debugging purposes, but its also the input for the next step -->
<p:store method="xml" include-content-type="false" indent="true">
<p:with-option name="href" select="resolve-uri('testimony-index.xml', $builddir)"/>
</p:store>
<!-- now convert the table, using the usage index just collected ... -->
<p:xslt name="testimony-table">
<p:input port="stylesheet"><p:document href="xslt/testimony-table.xsl"></p:document></p:input>
<p:input port="source"><p:pipe port="result" step="testimony-index"></p:pipe></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:with-param name="builddir-resolved" select="$builddir"/>
</p:xslt>
<!-- and directly store the resulting HTML file. -->
<p:store method="xhtml" include-content-type="false" indent="false">
<p:with-option name="href" select="resolve-uri('www/archive_testimonies.html', $builddir)"></p:with-option>
</p:store>
<p:xslt name="pseudo-testimonies" template-name="generate-pseudo-testimonies">
<p:input port="stylesheet"><p:document href="xslt/testimony-table.xsl"></p:document></p:input>
<p:input port="source"><p:pipe port="result" step="testimony-index"></p:pipe></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:with-param name="builddir-resolved" select="$builddir"/>
</p:xslt>
<!-- Store the generated fake TEI files -->
<p:for-each>
<p:iteration-source>
<p:pipe port="secondary" step="pseudo-testimonies"/>
</p:iteration-source>
<p:variable name="base-uri" select="p:base-uri()"/>
<p:identity name="pseudo-testimony-tei"/>
<p:store indent="true">
<p:with-option name="href" select="p:base-uri()"/>
</p:store>
<!-- and convert to html -->
<p:xslt>
<p:input port="source"><p:pipe port="result" step="pseudo-testimony-tei"/></p:input>
<p:input port="parameters"><p:pipe port="result" step="config"/></p:input>
<p:input port="stylesheet"><p:document href="xslt/single-testimony-html.xsl"/></p:input>
<p:with-param name="builddir-resolved" select="$builddir"></p:with-param>
</p:xslt>
<p:store encoding="utf-8" method="xhtml" include-content-type="false" indent="true">
<p:with-option name="href" select="p:resolve-uri(replace($base-uri, '.*/([^/.]*)\.xml$', '$1.html'), $testihtml)"/>
</p:store>
</p:for-each>
<p:identity><p:input port="source"><p:pipe port="result" step="testimony-index"/></p:input></p:identity>
</p:group>
</p:declare-step>