Statistics
| Revision:

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

History | View | Annotate | Download (8.3 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: graphics.xsl 9646 2011-11-05 23:39:08Z rahtz $</p>
71
         <p>Copyright: 2008, TEI Consortium</p>
72
      </desc>
73
   </doc>
74
    
75
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
76
      <desc>
77
        Convert Word drawing objects
78
    </desc>
79
   </doc>
80
    <xsl:template match="w:drawing">
81
      <xsl:param name="n" tunnel="yes"/>
82
        <xsl:choose>
83
            <xsl:when test="$convert-graphics='true'">
84
                <xsl:choose>
85
                    <xsl:when test="descendant::a:blip[1]/@r:embed">
86
                        <graphic>
87
			    <xsl:variable name="c">
88
			      <xsl:choose>
89
			      <xsl:when test="ancestor::w:tbl">
90
				<xsl:number level="any" from="w:tbl"/>
91
			      </xsl:when>
92
			      <xsl:otherwise>
93
				<xsl:number level="any"/>
94
			      </xsl:otherwise>
95
			      </xsl:choose>
96
			    </xsl:variable>
97
			    <xsl:attribute name="n">
98
			      <xsl:choose>
99
				<xsl:when test="number($n)">
100
				  <xsl:value-of select="($n * 100) + $c"/>
101
				</xsl:when>
102
				<xsl:otherwise>
103
				  <xsl:text>100</xsl:text>
104
				  <xsl:number level="any"/>
105
				</xsl:otherwise>
106
			      </xsl:choose>
107
			    </xsl:attribute>
108
			  <xsl:attribute name="width"
109
					 select="concat(number(descendant::wp:extent[1]/@cx) div 360000,'cm')"/>
110
			  <xsl:attribute name="height"
111
					 select="concat(number(descendant::wp:extent[1]/@cy) div 360000,'cm')"/>
112
				 <xsl:variable name="media-url" select="descendant::pic:cNvPr/@descr"/>
113
			 <xsl:choose>
114
				 <xsl:when test="starts-with($media-url,'movie::' )">
115
					 <xsl:attribute name="url">
116
						 <!-- The proper way to do it would be to extract the name from this
117
						      <xsl:value-of select="substring-after($media-url, 'movie::')"/>
118
						-->
119
						 <xsl:value-of select="descendant::pic:cNvPr/@name"/>
120
					 </xsl:attribute>
121
					 <xsl:attribute name="mimeType">video/x-something</xsl:attribute>
122
				 </xsl:when>
123

    
124
				 <xsl:otherwise>
125
					 <xsl:attribute name="url">
126
						 <xsl:variable name="rid" select="descendant::a:blip[1]/@r:embed"/>
127
						 <xsl:value-of select="document(concat($wordDirectory,'/word/_rels/document.xml.rels'))//rel:Relationship[@Id=$rid]/@Target"/>
128
					 </xsl:attribute>
129
				 </xsl:otherwise>
130
			 </xsl:choose>
131

    
132
				 <!-- inline or block -->
133
			  <xsl:attribute name="rend">
134
                                <xsl:choose>
135
                                    <xsl:when test="wp:anchor">block</xsl:when>
136
                                    <xsl:otherwise>inline</xsl:otherwise>
137
                                </xsl:choose>
138
                            </xsl:attribute>
139
			    <xsl:if test=".//wp:docPr/@descr">
140
			      <xsl:element name="desc">
141
				<xsl:value-of select=".//wp:docPr/@descr"/>
142
			      </xsl:element>
143
			    </xsl:if>                            
144
                        </graphic>
145
                    </xsl:when>
146
                    <xsl:otherwise>
147
                        <graphic> Linked Graphic: <xsl:variable name="rid" select="@r:link"/>
148
                            <xsl:value-of select="document(concat($wordDirectory,'/word/_rels/document.xml.rels'))//rel:Relationship[@Id=$rid]/@Target"/>
149
                        </graphic>
150
                    </xsl:otherwise>
151
                </xsl:choose>
152
            </xsl:when>
153
            <xsl:otherwise>
154
                <w:drawing>
155
                    <xsl:apply-templates mode="iden"/>
156
                </w:drawing>
157
            </xsl:otherwise>
158
        </xsl:choose>
159
    </xsl:template>
160
    
161
    <doc xmlns="http://www.oxygenxml.com/ns/doc/xsl">
162
      <desc>
163
        Guides the identity transformation of blips
164
    </desc>
165
   </doc>
166
    <xsl:template match="a:blip" mode="iden">
167
        <a:blip>
168
            <xsl:choose>
169
                <xsl:when test="@r:embed">
170
                    <xsl:variable name="rid" select="@r:embed"/>
171
                    <xsl:attribute name="r:embed">
172
                        <xsl:value-of select="document(concat($wordDirectory,'/word/_rels/document.xml.rels'))//rel:Relationship[@Id=$rid]/@Target"/>
173
                    </xsl:attribute>
174
                </xsl:when>
175
                <xsl:otherwise>
176
                    <xsl:variable name="rid" select="@r:link"/>
177
                    <xsl:attribute name="r:link">
178
                        <xsl:value-of select="document(concat($wordDirectory,'/word/_rels/document.xml.rels'))//rel:Relationship[@Id=$rid]/@Target"/>
179
                    </xsl:attribute>
180
                </xsl:otherwise>
181
            </xsl:choose>
182
            
183
        </a:blip>
184
    </xsl:template>
185
    
186
</xsl:stylesheet>