Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / docx / misc / check-docx-and-annotate.xsl @ 187

History | View | Annotate | Download (12.6 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3
                xmlns:dc="http://purl.org/dc/elements/1.1/"
4
                xmlns:dcterms="http://purl.org/dc/terms/"
5
                xmlns:dcmitype="http://purl.org/dc/dcmitype/"
6
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
7
                xmlns:tei="http://www.tei-c.org/ns/1.0"
8
                xmlns:iso="http://www.iso.org/ns/1.0"
9
                xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
10
                xmlns:xs="http://www.w3.org/2001/XMLSchema"
11
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
12
                xmlns:o="urn:schemas-microsoft-com:office:office"
13
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
14
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
15
                xmlns:v="urn:schemas-microsoft-com:vml"
16
                xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
17
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
18
                xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
19
                xmlns:w10="urn:schemas-microsoft-com:office:word"
20
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
21
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
22
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
23
                xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html"
24
                xmlns:con="http://schemas.openxmlformats.org/package/2006/content-types"
25
                xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
26
                xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
27
                version="2.0"
28
                exclude-result-prefixes="cp con ve o r m v wp w10 w wne mml tbx iso tei a xs pic fn xsi dc dcterms dcmitype">
29
    
30
    <xsl:output method="xml" version="1.0" encoding="UTF-8"/>
31
    
32
    <xsl:param name="word-directory">..</xsl:param>
33
    <xsl:param name="styleDoc">
34
        <xsl:value-of select="concat($wordDirectory, '/word/styles.xml')"/>
35
    </xsl:param>
36
    
37
    <xsl:key name="Styles" match="w:style/w:name" use="@w:val"/>
38
    
39
    <xsl:template match="/">
40
        <xsl:variable name="comments">
41
            <xsl:apply-templates mode="comments"/>
42
        </xsl:variable>
43
        <xsl:variable name="relations">
44
            <xsl:apply-templates select="doc(concat($wordDirectory,'/word/_rels/document.xml.rels'))"
45
                              mode="relations"/>
46
        </xsl:variable>
47
        <xsl:variable name="content-types">
48
            <xsl:apply-templates mode="content-types" select="doc(concat($wordDirectory,'/Content_Types.xml'))"/>
49
        </xsl:variable>
50
        
51
        <xsl:message>produce actual document</xsl:message>
52
        <xsl:apply-templates mode="document"/>    
53
        
54
        <xsl:message>write out relations</xsl:message>
55
        <xsl:call-template name="write-out-relations">
56
            <xsl:with-param name="relations" select="$relations"/>
57
        </xsl:call-template>
58

    
59
        <xsl:message>write out content types</xsl:message>
60
        <xsl:call-template name="write-out-content-types">
61
            <xsl:with-param name="types" select="$content-types"/>
62
        </xsl:call-template>
63
        
64

    
65
        <xsl:message>write out comments</xsl:message>
66
        <xsl:call-template name="write-out-comments">
67
            <xsl:with-param name="comments" select="$comments"/>
68
        </xsl:call-template>
69
        
70
        <xsl:message>lock down document</xsl:message>
71
        <xsl:call-template name="lock-down-document"/>
72
    </xsl:template>
73
    
74
    <!-- identity transform  document-->
75
    <xsl:template match="@*|text()|comment()|processing-instruction()" mode="document">
76
        <xsl:copy-of select="."/>
77
    </xsl:template>
78
    
79
    <xsl:template match="*" mode="document">
80
        <xsl:copy>
81
            <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="document"/>
82
        </xsl:copy>
83
    </xsl:template>
84
    
85
    <!-- identity transform relations -->
86
    <xsl:template match="@*|text()|comment()|processing-instruction()" mode="relations">
87
        <xsl:copy-of select="."/>
88
    </xsl:template>
89
    
90
    <xsl:template match="*" mode="relations">
91
        <xsl:copy>
92
            <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="document"/>
93
        </xsl:copy>
94
    </xsl:template>
95
    
96
    <!-- copy nothing for comments -->
97
    <xsl:template match="@*|text()|comment()|processing-instruction()" mode="comments"/>
98
        
99
    
100
    <xsl:template match="*" mode="comments">
101
        <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="comments"/>
102
    </xsl:template>
103
    
104
    <!-- identity transform content types -->
105
    <xsl:template match="@*|text()|comment()|processing-instruction()" mode="content-types">
106
        <xsl:copy-of select="."/>
107
    </xsl:template>
108
    
109
    <xsl:template match="*" mode="content-types">
110
        <xsl:copy>
111
            <xsl:apply-templates select="*|@*|processing-instruction()|comment()|text()" mode="content-types"/>
112
        </xsl:copy>
113
    </xsl:template>    
114

    
115
    <!-- comment helper -->
116
    <xsl:template name="create-comment">
117
        <xsl:param name="id"/>
118
        <xsl:param name="text"/>
119
        <w:comment w:id="{$id}" w:author="TEIISO" w:date="2008-09-28T14:17:00Z" w:initials="SPQR">
120
            <w:p>
121
                <w:pPr>
122
                    <w:pStyle w:val="CommentText"/>
123
                </w:pPr>
124
                <w:r>
125
                    <w:annotationRef/>
126
		</w:r>
127
		<xsl:apply-templates select="$text"/>
128
            </w:p>
129
        </w:comment>
130
    </xsl:template>
131
    
132
    <!-- put back correct styles -->
133
    <xsl:template match="w:pStyle" mode="document">
134
        <w:pStyle>
135
            <xsl:attribute name="w:val">
136
                <xsl:call-template name="getStyleName">
137
                    <xsl:with-param name="in" select="@w:val"/>
138
                </xsl:call-template>
139
            </xsl:attribute>
140
        </w:pStyle>
141
    </xsl:template>
142
    
143
    <xsl:template match="w:rStyle" mode="document">
144
        <w:rStyle>
145
            <xsl:attribute name="w:val">
146
                <xsl:call-template name="getStyleName">
147
                    <xsl:with-param name="in" select="@w:val"/>
148
                </xsl:call-template>
149
            </xsl:attribute>
150
        </w:rStyle>
151
    </xsl:template>
152
    
153

    
154
    <xsl:template name="getStyleName">
155
        <xsl:param name="in"/>
156
        <xsl:for-each select="document($styleDoc,/)">
157
            <xsl:for-each select="key('Styles',$in)">
158
                <xsl:value-of select="parent::w:style/@w:styleId"/>
159
            </xsl:for-each>
160
        </xsl:for-each>
161
    </xsl:template>
162
    
163
    
164
    <!-- content types -->
165
    <xsl:template match="con:Override[@PartName='/word/comments.xml']"/>
166
    <!-- write out content-types -->
167
    <xsl:template name="write-out-content-types">
168
        <xsl:param name="types"/>
169
	     <xsl:if test="$debug='true'">
170
	        <xsl:message>Writing out <xsl:value-of select="concat($wordDirectory,'/Content_Types_new.xml')"/>
171
         </xsl:message>
172
	     </xsl:if>
173
        <xsl:result-document href="{concat($wordDirectory,'/Content_Types_new.xml')}" standalone="yes">
174
            <Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
175
                <xsl:for-each select="$types/child::node()/*">
176
                    <xsl:copy-of select="."/>
177
                </xsl:for-each>
178
                <Override PartName="/word/comments.xml"
179
                      ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml"/>
180
            </Types>
181
        </xsl:result-document>
182
    </xsl:template>
183
    
184
    
185
    <!-- write out relations -->
186
    <xsl:template name="write-out-relations">
187
        <xsl:param name="relations"/>
188
	     <xsl:if test="$debug='true'">
189
	        <xsl:message>Writing out <xsl:value-of select="concat($wordDirectory,'word/_rels/document_new.xml.rels')"/>
190
         </xsl:message>
191
	     </xsl:if>
192
        <xsl:result-document href="{concat($wordDirectory,'/word/_rels/document_new.xml.rels')}"
193
                           standalone="yes">
194
            <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
195
                <xsl:for-each select="$relations/child::node()/*">
196
                    <xsl:copy-of select="."/>
197
                </xsl:for-each>
198
                <Relationship Id="rId9999"
199
                          Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/comments"
200
                          Target="comments.xml"/>
201
            </Relationships>
202
        </xsl:result-document>
203
    </xsl:template>
204
    
205
    <!-- write out comments -->
206
    <xsl:template name="write-out-comments">
207
        <xsl:param name="comments"/>
208
	     <xsl:if test="$debug='true'">
209
	        <xsl:message>Writing out <xsl:value-of select="concat($wordDirectory,'word/_rels/comments.xml')"/>
210
         </xsl:message>
211
	     </xsl:if>
212
        <xsl:result-document href="{concat($wordDirectory,'/word/comments.xml')}" standalone="yes">
213
            <w:comments xmlns:mv="urn:schemas-microsoft-com:mac:vml"
214
                     xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main">
215
                <xsl:copy-of select="$comments"/>
216
            </w:comments>
217
        </xsl:result-document>
218
    </xsl:template>
219
    
220
    <!-- writes settings.xml and app.xml to lock down the document -->
221
    <xsl:template name="lock-down-document">
222
        <xsl:result-document href="{concat($wordDirectory,'/docProps/app.xml')}" standalone="yes">
223
            <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"
224
                     xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
225
                <Template>STD_3_0_0.dotx</Template>
226
                <Application>TEIISO tei-docx.xsl</Application>
227
                <DocSecurity>8</DocSecurity>
228
                <SharedDoc>true</SharedDoc>
229
                <AppVersion>1.0</AppVersion>
230
            </Properties>
231
        </xsl:result-document>
232
        
233
        <xsl:result-document href="{concat($wordDirectory,'/word/settings.xml')}" standalone="yes">
234
            <w:settings xmlns:sl="http://schemas.openxmlformats.org/schemaLibrary/2006/main">
235
                <w:zoom w:percent="100"/>
236
                <w:attachedTemplate r:id="rId1"/>
237
                <w:linkStyles/>
238
                <w:doNotTrackMoves/>
239
                <w:documentProtection w:edit="readOnly" w:enforcement="1"/>
240
                <w:defaultTabStop w:val="720"/>
241
                <w:hyphenationZone w:val="425"/>
242
                <w:evenAndOddHeaders/>
243
                <w:drawingGridHorizontalSpacing w:val="110"/>
244
                <w:displayHorizontalDrawingGridEvery w:val="2"/>
245
                <w:characterSpacingControl w:val="doNotCompress"/>
246
                <w:hdrShapeDefaults>
247
                    <o:shapedefaults v:ext="edit" spidmax="2050"/>
248
                </w:hdrShapeDefaults>
249
                <w:compat/>
250
                <w:rsids/>
251
                <m:mathPr>
252
                    <m:mathFont m:val="MT Symbol"/>
253
                    <m:brkBin m:val="before"/>
254
                    <m:brkBinSub m:val="--"/>
255
                    <m:smallFrac m:val="off"/>
256
                    <m:dispDef/>
257
                    <m:lMargin m:val="0"/>
258
                    <m:rMargin m:val="0"/>
259
                    <m:defJc m:val="centerGroup"/>
260
                    <m:wrapIndent m:val="1440"/>
261
                    <m:intLim m:val="subSup"/>
262
                    <m:naryLim m:val="undOvr"/>
263
                </m:mathPr>
264
                <w:attachedSchema w:val="ActionsPane3"/>
265
                <w:themeFontLang w:val="en-GB"/>
266
                <w:clrSchemeMapping w:bg1="light1" w:t1="dark1" w:bg2="light2" w:t2="dark2" w:accent1="accent1"
267
                                w:accent2="accent2"
268
                                w:accent3="accent3"
269
                                w:accent4="accent4"
270
                                w:accent5="accent5"
271
                                w:accent6="accent6"
272
                                w:hyperlink="hyperlink"
273
                                w:followedHyperlink="followedHyperlink"/>
274
                <w:shapeDefaults>
275
                    <o:shapedefaults v:ext="edit" spidmax="2050"/>
276
                    <o:shapelayout v:ext="edit">
277
                        <o:idmap v:ext="edit" data="1"/>
278
                    </o:shapelayout>
279
                </w:shapeDefaults>
280
                <w:decimalSymbol w:val="."/>
281
                <w:listSeparator w:val=","/>
282
            </w:settings>
283
            
284
        </xsl:result-document>
285
    </xsl:template>
286
</xsl:stylesheet>