forked from faustedition/faust-gen-html
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestimony.xpl
177 lines (138 loc) · 7.81 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
<?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: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:import href="http://xproc.org/library/recursive-directory-list.xpl"/>
<p:import href="http://xmlcalabash.com/extension/steps/library-1.0.xpl"/>
<!-- Parameter laden -->
<p:parameters name="config">
<p:input port="parameters">
<p:document href="config.xml"/>
<p:pipe port="parameters" step="main"></p:pipe>
</p:input>
</p:parameters>
<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="testimony-xml">
<p:with-option name="output-base-uri" select="p:base-uri()"/>
<p:input port="source"><p:pipe port="result" step="load-testimony"/></p:input>
<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:identity name="single-testimony-tei"/>
<p:store indent="true">
<p:with-option name="href" select="p:base-uri()"/>
</p:store>
<p:xslt>
<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="p:resolve-uri(replace(p:base-uri(), '.*/([^/.]*)\.xml$', '$1.html'), $testihtml)"/>
</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>
<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>