Statistics
| Revision:

root / tmp / org.txm.core / res / org / txm / xml / xsl / tei / docx / from / lists / lists.xsl @ 187

History | View | Annotate | Download (8.8 kB)

1
<?xml version="1.0" encoding="utf-8"?>
2
<xsl:stylesheet xmlns:xs="http://www.w3.org/2001/XMLSchema"
3
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4
                xmlns:prop="http://schemas.openxmlformats.org/officeDocument/2006/custom-properties"
5
                xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
6
                xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
7
                xmlns:dc="http://purl.org/dc/elements/1.1/"
8
                xmlns:dcterms="http://purl.org/dc/terms/"
9
                xmlns:dcmitype="http://purl.org/dc/dcmitype/"
10
                xmlns:iso="http://www.iso.org/ns/1.0"
11
                xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
12
                xmlns:mml="http://www.w3.org/1998/Math/MathML"
13
                xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
14
                xmlns:mv="urn:schemas-microsoft-com:mac:vml"
15
                xmlns:o="urn:schemas-microsoft-com:office:office"
16
                xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
17
                xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
18
                xmlns:rel="http://schemas.openxmlformats.org/package/2006/relationships"
19
                xmlns:tbx="http://www.lisa.org/TBX-Specification.33.0.html"
20
                xmlns:tei="http://www.tei-c.org/ns/1.0"
21
                xmlns:teidocx="http://www.tei-c.org/ns/teidocx/1.0"
22
                xmlns:v="urn:schemas-microsoft-com:vml"
23
                xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006"
24
                xmlns:w10="urn:schemas-microsoft-com:office:word"
25
                xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
26
                xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
27
                xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
28
                
29
                xmlns="http://www.tei-c.org/ns/1.0"
30
                version="2.0"
31
                exclude-result-prefixes="a cp dc dcterms dcmitype prop     iso m mml mo mv o pic r rel     tbx tei teidocx v xs ve w10 w wne wp">
32
    
33
    
34
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl" scope="stylesheet" type="stylesheet">
35
      <desc>
36
         <p> TEI stylesheet for converting Word docx files to TEI </p>
37
         <p>This software is dual-licensed:
38

    
39
1. Distributed under a Creative Commons Attribution-ShareAlike 3.0
40
Unported License http://creativecommons.org/licenses/by-sa/3.0/ 
41

    
42
2. http://www.opensource.org/licenses/BSD-2-Clause
43
		
44
All rights reserved.
45

    
46
Redistribution and use in source and binary forms, with or without
47
modification, are permitted provided that the following conditions are
48
met:
49

    
50
* Redistributions of source code must retain the above copyright
51
notice, this list of conditions and the following disclaimer.
52

    
53
* Redistributions in binary form must reproduce the above copyright
54
notice, this list of conditions and the following disclaimer in the
55
documentation and/or other materials provided with the distribution.
56

    
57
This software is provided by the copyright holders and contributors
58
"as is" and any express or implied warranties, including, but not
59
limited to, the implied warranties of merchantability and fitness for
60
a particular purpose are disclaimed. In no event shall the copyright
61
holder or contributors be liable for any direct, indirect, incidental,
62
special, exemplary, or consequential damages (including, but not
63
limited to, procurement of substitute goods or services; loss of use,
64
data, or profits; or business interruption) however caused and on any
65
theory of liability, whether in contract, strict liability, or tort
66
(including negligence or otherwise) arising in any way out of the use
67
of this software, even if advised of the possibility of such damage.
68
</p>
69
         <p>Author: See AUTHORS</p>
70
         <p>Id: $Id: lists.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
71
         <p>Copyright: 2008, TEI Consortium</p>
72
      </desc>
73
   </doc>
74
    
75
    
76
    <!-- 
77
        This template handles lists and takes care of nested lists.
78
    -->
79
    <xsl:template name="listSection">
80
        <xsl:variable name="level">
81
            <xsl:value-of select="w:pPr/w:pStyle/@w:val"/>
82
        </xsl:variable>
83
        <list>
84
	  <xsl:call-template name="listType"/>
85
	  
86
	  <!-- ISO Notes are be handled by a specific handler -->
87
	  <xsl:for-each-group select="current-group()"
88
			      group-adjacent="if(w:pPr/w:pStyle/@w:val=$level)  then 0 
89
					      else if(w:pPr/w:pStyle/@w:val='Note') then 0                 
90
					      else if(w:pPr/w:pStyle/@w:val='dl') then 1                
91
					      else 1">
92
	    <xsl:choose>
93
	      <!-- we are still on the same level -->
94
	      <xsl:when test="current-grouping-key()=0">
95
		<xsl:for-each select="current-group()">
96
		  <!-- put items and notes as siblings  for now -->
97
		  <xsl:choose>
98
		    <xsl:when test="tei:is-list(.)">
99
		      <item>
100
			<xsl:apply-templates/>
101
		      </item>
102
		    </xsl:when>
103
		    <xsl:otherwise>
104
		      <xsl:apply-templates select="." mode="paragraph"/>
105
		    </xsl:otherwise>
106
		  </xsl:choose>
107
		</xsl:for-each>
108
	      </xsl:when>
109
	      <xsl:otherwise>
110
		<xsl:call-template name="listSection"/>
111
	      </xsl:otherwise>
112
	    </xsl:choose>
113
	    
114
	  </xsl:for-each-group>
115
        </list>
116
    </xsl:template>
117
    
118
    <!--
119
        Trying to figure out the style of a list.
120
    -->
121
    <xsl:template name="listType">
122
        <xsl:variable name="style">
123
            <xsl:value-of select="w:pPr/w:pStyle/@w:val"/>
124
        </xsl:variable>
125
        <xsl:variable name="type" select="tei:get-listtype($style)"/>
126
        
127
        <xsl:attribute name="type">
128
            <xsl:choose>
129
                <xsl:when test="string-length($type) &gt; 0">
130
                    <xsl:value-of select="$type"/>
131
                </xsl:when>
132
                
133
                <!-- try to figure it out by looking at the corresponding numbering file -->
134
                <xsl:otherwise>
135
                    
136
                    <!-- look up the numbering definition .. either in document.xml or in styles.xml  -->
137
                    <xsl:variable name="numbering-def">
138
                        <xsl:choose>
139
                            <xsl:when test="w:pPr/w:numPr/w:numId/@w:val">
140
                                <xsl:value-of select="w:pPr/w:numPr/w:numId/@w:val"/>
141
                            </xsl:when>
142
                            <xsl:otherwise>
143
                                <!-- we might want to follow the basedOn reference, but not at the moment -->
144
                                <xsl:value-of select="document(concat($wordDirectory,'/word/styles.xml'))//w:style[w:name/@w:val=$style]/w:pPr/w:numPr/w:numId/@w:val"/>
145
                            </xsl:otherwise>
146
                        </xsl:choose>
147
                    </xsl:variable>
148
                    
149
                    <!-- look up the level .. either in document.xml or in styles.xml  -->
150
                    <xsl:variable name="numbering-level">
151
                        <xsl:choose>
152
                            <xsl:when test="w:pPr/w:numPr/w:ilvl/@w:val">
153
                                <xsl:value-of select="w:pPr/w:numPr/w:ilvl/@w:val"/>
154
                            </xsl:when>
155
                            <xsl:otherwise>
156
                                <!-- we might want to follow the basedOn reference, but not at the moment -->
157
                                <xsl:value-of select="document(concat($wordDirectory,'/word/styles.xml'))//w:style[w:name/@w:val=$style]/w:pPr/w:numPr/w:ilvl/@w:val"/>
158
                            </xsl:otherwise>
159
                        </xsl:choose>
160
                    </xsl:variable>
161
                    
162
                    <!-- find the abstract numbering definition and then the corresponding numfmt -->
163
                    <xsl:variable name="abstract-def"
164
                             select="document(concat($wordDirectory,'/word/numbering.xml'))//w:num[@w:numId=$numbering-def]/w:abstractNumId/@w:val"/>
165
                    <xsl:variable name="numfmt">
166
                        <xsl:value-of select="document(concat($wordDirectory,'/word/numbering.xml'))//w:abstractNum[@w:abstractNumId=$abstract-def]/w:lvl[@w:ilvl=$numbering-level]/w:numFmt/@w:val"/>
167
                    </xsl:variable>
168
                    
169
                    
170
                    <!-- figure out what numbering scheme to use -->
171
                    <xsl:choose>
172
		        <xsl:when test="$style='dl'">gloss</xsl:when>
173
                        <xsl:when test="string-length($numfmt)=0">unordered</xsl:when>
174
                        <xsl:when test="$numfmt='bullet'">unordered</xsl:when>
175
                        <xsl:otherwise>ordered</xsl:otherwise>
176
                    </xsl:choose>
177
                </xsl:otherwise>
178
            </xsl:choose>
179
        </xsl:attribute>
180
    </xsl:template>
181
    
182
    
183
</xsl:stylesheet>