avv2word 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,124 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:v="urn:schemas-microsoft-com:vml"
5
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
8
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
9
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11
+ xmlns:java="http://xml.apache.org/xalan/java"
12
+ xmlns:str="http://exslt.org/strings"
13
+ xmlns:func="http://exslt.org/functions"
14
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
15
+ version="1.0"
16
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
+ extension-element-prefixes="func">
18
+ <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
19
+ <xsl:include href="./functions.xslt"/>
20
+ <xsl:include href="./tables.xslt"/>
21
+
22
+ <xsl:template match="footer">
23
+ <w:ftr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
24
+ xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
25
+ xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
26
+ xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
27
+ xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
28
+ xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
29
+ xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
30
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
31
+ xmlns:o="urn:schemas-microsoft-com:office:office"
32
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
33
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
34
+ xmlns:v="urn:schemas-microsoft-com:vml"
35
+ xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
36
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
37
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
38
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
39
+ xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
40
+ xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
41
+ xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
42
+ xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
43
+ xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
44
+ xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
45
+ mc:Ignorable="w14 w15 wp14">
46
+ <xsl:apply-templates />
47
+ </w:ftr>
48
+ </xsl:template>
49
+
50
+ <xsl:template match="p[ancestor::footer]">
51
+ <w:p>
52
+ <xsl:call-template name="text-alignment" />
53
+ <xsl:apply-templates />
54
+ </w:p>
55
+ </xsl:template>
56
+
57
+ <xsl:template name="text-alignment">
58
+ <xsl:param name="class" select="@class" />
59
+ <xsl:param name="style" select="@style" />
60
+ <xsl:param name="line-height" select="@line-height" />
61
+ <xsl:param name="margin-bottom" select="@margin-bottom" />
62
+ <xsl:param name="margin-top" select="@margin-top" />
63
+ <xsl:param name="text-indent" select="@text-indent" />
64
+ <xsl:param name="text-hanging" select="@text-hanging" />
65
+ <xsl:variable name="alignment">
66
+ <xsl:choose>
67
+ <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
68
+ <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
69
+ <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
70
+ <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
71
+ <xsl:otherwise></xsl:otherwise>
72
+ </xsl:choose>
73
+ </xsl:variable>
74
+ <xsl:variable name="indent">
75
+ <xsl:choose>
76
+ <xsl:when test="$text-indent &gt; 0"><xsl:value-of select="$text-indent"/></xsl:when>
77
+ <xsl:otherwise></xsl:otherwise>
78
+ </xsl:choose>
79
+ </xsl:variable>
80
+ <xsl:variable name="hanging">
81
+ <xsl:choose>
82
+ <xsl:when test="string-length(normalize-space($indent)) > 0 and string-length(normalize-space($text-hanging)) > 0"><xsl:value-of select="$text-hanging"/></xsl:when>
83
+ <xsl:when test="string-length(normalize-space($indent)) > 0">0</xsl:when>
84
+ <xsl:otherwise></xsl:otherwise>
85
+ </xsl:choose>
86
+ </xsl:variable>
87
+ <xsl:variable name="height">
88
+ <xsl:choose>
89
+ <xsl:when test="string-length($line-height) > 0"><xsl:value-of select="@line-height"/></xsl:when>
90
+ <xsl:otherwise>336</xsl:otherwise>
91
+ </xsl:choose>
92
+ </xsl:variable>
93
+ <xsl:variable name="bottom">
94
+ <xsl:choose>
95
+ <xsl:when test="string-length($margin-bottom) > 0"><xsl:value-of select="@margin-bottom"/></xsl:when>
96
+ <xsl:otherwise>112</xsl:otherwise>
97
+ </xsl:choose>
98
+ </xsl:variable>
99
+ <xsl:variable name="top">
100
+ <xsl:choose>
101
+ <xsl:when test="string-length($margin-top) > 0"><xsl:value-of select="@margin-top"/></xsl:when>
102
+ <xsl:otherwise>0</xsl:otherwise>
103
+ </xsl:choose>
104
+ </xsl:variable>
105
+ <w:pPr>
106
+ <w:spacing w:lineRule="atLeast" w:line="{$height}" w:before="{$top}" w:after="{$bottom}"/>
107
+ <xsl:choose>
108
+ <xsl:when test="string-length(normalize-space($alignment)) > 0 and string-length(normalize-space($indent)) > 0">
109
+ <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
110
+ <w:jc w:val="{$alignment}"/>
111
+ </xsl:when>
112
+ <xsl:when test="string-length(normalize-space($indent)) > 0">
113
+ <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
114
+ </xsl:when>
115
+ <xsl:when test="string-length(normalize-space($alignment)) > 0">
116
+ <w:jc w:val="{$alignment}"/>
117
+ </xsl:when>
118
+ </xsl:choose>
119
+ </w:pPr>
120
+ </xsl:template>
121
+
122
+ <xsl:template match="*[not(descendant-or-self::footer)]"/>
123
+
124
+ </xsl:stylesheet>
@@ -0,0 +1,37 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:v="urn:schemas-microsoft-com:vml"
5
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
8
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
9
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11
+ xmlns:java="http://xml.apache.org/xalan/java"
12
+ xmlns:str="http://exslt.org/strings"
13
+ xmlns:func="http://exslt.org/functions"
14
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
15
+ version="1.0"
16
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
+ extension-element-prefixes="func">
18
+
19
+ <!-- support function to return substring-before or everything -->
20
+ <func:function name="func:substring-before-if-contains">
21
+ <xsl:param name="arg"/>
22
+ <xsl:param name="delim"/>
23
+ <func:result>
24
+ <xsl:choose>
25
+ <xsl:when test="contains($arg, $delim)">
26
+ <xsl:value-of select="substring-before($arg, $delim)"/>
27
+ </xsl:when>
28
+ <xsl:otherwise>
29
+ <xsl:value-of select="$arg"/>
30
+ </xsl:otherwise>
31
+ </xsl:choose>
32
+ </func:result>
33
+ </func:function>
34
+
35
+ <!-- template as function used to return the relationship id of the element (currently links or images) -->
36
+ <xsl:template name="relationship-id">rId<xsl:value-of select="count(preceding::a[starts-with(@href, 'http://') or starts-with(@href, 'https://')])+count(preceding::img)+8"/></xsl:template>
37
+ </xsl:stylesheet>
@@ -0,0 +1,124 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:v="urn:schemas-microsoft-com:vml"
5
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
8
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
9
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11
+ xmlns:java="http://xml.apache.org/xalan/java"
12
+ xmlns:str="http://exslt.org/strings"
13
+ xmlns:func="http://exslt.org/functions"
14
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
15
+ version="1.0"
16
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
+ extension-element-prefixes="func">
18
+ <xsl:output method="xml" encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
19
+ <xsl:include href="./functions.xslt"/>
20
+ <xsl:include href="./tables.xslt"/>
21
+
22
+ <xsl:template match="header">
23
+ <w:hdr xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
24
+ xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
25
+ xmlns:cx1="http://schemas.microsoft.com/office/drawing/2015/9/8/chartex"
26
+ xmlns:cx2="http://schemas.microsoft.com/office/drawing/2015/10/21/chartex"
27
+ xmlns:cx3="http://schemas.microsoft.com/office/drawing/2016/5/9/chartex"
28
+ xmlns:cx4="http://schemas.microsoft.com/office/drawing/2016/5/10/chartex"
29
+ xmlns:cx5="http://schemas.microsoft.com/office/drawing/2016/5/11/chartex"
30
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
31
+ xmlns:o="urn:schemas-microsoft-com:office:office"
32
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
33
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
34
+ xmlns:v="urn:schemas-microsoft-com:vml"
35
+ xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
36
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
37
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
38
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
39
+ xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
40
+ xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
41
+ xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
42
+ xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
43
+ xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
44
+ xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
45
+ mc:Ignorable="w14 w15 wp14">
46
+ <xsl:apply-templates />
47
+ </w:hdr>
48
+ </xsl:template>
49
+
50
+ <xsl:template match="p[ancestor::header]">
51
+ <w:p>
52
+ <xsl:call-template name="text-alignment" />
53
+ <xsl:apply-templates />
54
+ </w:p>
55
+ </xsl:template>
56
+
57
+ <xsl:template name="text-alignment">
58
+ <xsl:param name="class" select="@class" />
59
+ <xsl:param name="style" select="@style" />
60
+ <xsl:param name="line-height" select="@line-height" />
61
+ <xsl:param name="margin-bottom" select="@margin-bottom" />
62
+ <xsl:param name="margin-top" select="@margin-top" />
63
+ <xsl:param name="text-indent" select="@text-indent" />
64
+ <xsl:param name="text-hanging" select="@text-hanging" />
65
+ <xsl:variable name="alignment">
66
+ <xsl:choose>
67
+ <xsl:when test="contains(concat(' ', $class, ' '), ' center ') or contains(translate(normalize-space($style),' ',''), 'text-align:center')">center</xsl:when>
68
+ <xsl:when test="contains(concat(' ', $class, ' '), ' right ') or contains(translate(normalize-space($style),' ',''), 'text-align:right')">right</xsl:when>
69
+ <xsl:when test="contains(concat(' ', $class, ' '), ' left ') or contains(translate(normalize-space($style),' ',''), 'text-align:left')">left</xsl:when>
70
+ <xsl:when test="contains(concat(' ', $class, ' '), ' justify ') or contains(translate(normalize-space($style),' ',''), 'text-align:justify')">both</xsl:when>
71
+ <xsl:otherwise></xsl:otherwise>
72
+ </xsl:choose>
73
+ </xsl:variable>
74
+ <xsl:variable name="indent">
75
+ <xsl:choose>
76
+ <xsl:when test="$text-indent &gt; 0"><xsl:value-of select="$text-indent"/></xsl:when>
77
+ <xsl:otherwise></xsl:otherwise>
78
+ </xsl:choose>
79
+ </xsl:variable>
80
+ <xsl:variable name="hanging">
81
+ <xsl:choose>
82
+ <xsl:when test="string-length(normalize-space($indent)) > 0 and string-length(normalize-space($text-hanging)) > 0"><xsl:value-of select="$text-hanging"/></xsl:when>
83
+ <xsl:when test="string-length(normalize-space($indent)) > 0">0</xsl:when>
84
+ <xsl:otherwise></xsl:otherwise>
85
+ </xsl:choose>
86
+ </xsl:variable>
87
+ <xsl:variable name="height">
88
+ <xsl:choose>
89
+ <xsl:when test="string-length($line-height) > 0"><xsl:value-of select="@line-height"/></xsl:when>
90
+ <xsl:otherwise>336</xsl:otherwise>
91
+ </xsl:choose>
92
+ </xsl:variable>
93
+ <xsl:variable name="bottom">
94
+ <xsl:choose>
95
+ <xsl:when test="string-length($margin-bottom) > 0"><xsl:value-of select="@margin-bottom"/></xsl:when>
96
+ <xsl:otherwise>112</xsl:otherwise>
97
+ </xsl:choose>
98
+ </xsl:variable>
99
+ <xsl:variable name="top">
100
+ <xsl:choose>
101
+ <xsl:when test="string-length($margin-top) > 0"><xsl:value-of select="@margin-top"/></xsl:when>
102
+ <xsl:otherwise>0</xsl:otherwise>
103
+ </xsl:choose>
104
+ </xsl:variable>
105
+ <w:pPr>
106
+ <w:spacing w:lineRule="atLeast" w:line="{$height}" w:before="{$top}" w:after="{$bottom}"/>
107
+ <xsl:choose>
108
+ <xsl:when test="string-length(normalize-space($alignment)) > 0 and string-length(normalize-space($indent)) > 0">
109
+ <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
110
+ <w:jc w:val="{$alignment}"/>
111
+ </xsl:when>
112
+ <xsl:when test="string-length(normalize-space($indent)) > 0">
113
+ <w:ind w:left="{$indent}" w:hanging="{$hanging}"/>
114
+ </xsl:when>
115
+ <xsl:when test="string-length(normalize-space($alignment)) > 0">
116
+ <w:jc w:val="{$alignment}"/>
117
+ </xsl:when>
118
+ </xsl:choose>
119
+ </w:pPr>
120
+ </xsl:template>
121
+
122
+ <xsl:template match="*[not(descendant-or-self::header)]"/>
123
+
124
+ </xsl:stylesheet>
@@ -0,0 +1,21 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3
+ xmlns:o="urn:schemas-microsoft-com:office:office"
4
+ xmlns:v="urn:schemas-microsoft-com:vml"
5
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
6
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
7
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
8
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
9
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
10
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
11
+ xmlns:java="http://xml.apache.org/xalan/java"
12
+ xmlns:str="http://exslt.org/strings"
13
+ xmlns:func="http://exslt.org/functions"
14
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
15
+ version="1.0"
16
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
17
+ extension-element-prefixes="func">
18
+ <xsl:import href="./base.xslt"/>
19
+ <!--Extra templates and customizations-->
20
+ <xsl:include href="./extras.xslt"/>
21
+ </xsl:stylesheet>
@@ -0,0 +1,148 @@
1
+ <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
3
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
4
+ xmlns:o="urn:schemas-microsoft-com:office:office"
5
+ xmlns:v="urn:schemas-microsoft-com:vml"
6
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
7
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
8
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
9
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
10
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
11
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
12
+ xmlns:java="http://xml.apache.org/xalan/java"
13
+ xmlns:str="http://exslt.org/strings"
14
+ xmlns:func="http://exslt.org/functions"
15
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
16
+ version="1.0"
17
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
18
+ extension-element-prefixes="func">
19
+
20
+ <!-- template as function used to return the file extension of an image. -->
21
+ <xsl:template name="image-extension">
22
+ <xsl:param name="data-filename" select="." />
23
+ <xsl:param name="source" select="." />
24
+ <xsl:variable name="filename">
25
+ <xsl:call-template name="image-name">
26
+ <xsl:with-param name="source" select="$source"/>
27
+ <xsl:with-param name="data-filename" select="$data-filename"/>
28
+ </xsl:call-template>
29
+ </xsl:variable>
30
+ <xsl:value-of select="substring-after($filename,'.')"/>
31
+ </xsl:template>
32
+
33
+ <!-- template as function used to return the name of an image. -->
34
+ <xsl:template name="image-name">
35
+ <xsl:param name="data-filename" select="." />
36
+ <xsl:param name="source" select="." />
37
+ <xsl:choose>
38
+ <xsl:when test="string-length($data-filename) > 0">
39
+ <xsl:value-of select="$data-filename"/>
40
+ </xsl:when>
41
+ <xsl:otherwise>
42
+ <xsl:call-template name="extract-filename-from-path">
43
+ <xsl:with-param name="path" select="$source"/>
44
+ </xsl:call-template>
45
+ </xsl:otherwise>
46
+ </xsl:choose>
47
+ </xsl:template>
48
+
49
+ <!-- template as function used to extract the filename from the image source. Can't use tokenize or other functions which return a fragment tree as xpath can't process them. -->
50
+ <xsl:template name="extract-filename-from-path">
51
+ <xsl:param name="path" select="." />
52
+ <xsl:choose>
53
+ <xsl:when test="not(contains($path, '/'))">
54
+ <xsl:value-of select="$path" />
55
+ </xsl:when>
56
+ <xsl:otherwise>
57
+ <xsl:call-template name="extract-filename-from-path">
58
+ <xsl:with-param name="path" select="substring-after($path, '/')" />
59
+ </xsl:call-template>
60
+ </xsl:otherwise>
61
+ </xsl:choose>
62
+ </xsl:template>
63
+
64
+ <!--
65
+ Returns the unqualified dimension from a length specification copied from:
66
+ http://docbook.sourceforge.net/release/xsl/1.76.1/doc/lib/length-magnitude.html
67
+ -->
68
+
69
+ <xsl:template name="length-magnitude">
70
+ <xsl:param name="length" select="'0pt'"></xsl:param>
71
+
72
+ <xsl:choose>
73
+ <xsl:when test="string-length($length) = 0"></xsl:when>
74
+ <xsl:when test="substring($length,1,1) = '0' or substring($length,1,1) = '1' or substring($length,1,1) = '2' or substring($length,1,1) = '3' or substring($length,1,1) = '4' or substring($length,1,1) = '5' or substring($length,1,1) = '6' or substring($length,1,1) = '7' or substring($length,1,1) = '8' or substring($length,1,1) = '9' or substring($length,1,1) = '.'">
75
+ <xsl:value-of select="substring($length,1,1)"></xsl:value-of>
76
+ <xsl:call-template name="length-magnitude">
77
+ <xsl:with-param name="length" select="substring($length,2)"></xsl:with-param>
78
+ </xsl:call-template>
79
+ </xsl:when>
80
+ </xsl:choose>
81
+ </xsl:template>
82
+
83
+
84
+
85
+
86
+ <!-- Convert em and pixel sizes to inches. Inspired by from:
87
+ http://docbook.sourceforge.net/release/xsl/1.76.1/doc/lib/length-in-points.html
88
+ EMU info from: https://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
89
+ -->
90
+ <xsl:template name="length-in-emus">
91
+ <xsl:param name="length" select="'0px'"/>
92
+ <xsl:param name="em.size" select="6.02250006023"/>
93
+ <xsl:param name="pixels.per.inch" select="90"/>
94
+ <xsl:variable name="emus.per.inch" select="914400"/>
95
+
96
+ <xsl:variable name="magnitude">
97
+ <xsl:call-template name="length-magnitude">
98
+ <xsl:with-param name="length" select="$length"/>
99
+ </xsl:call-template>
100
+ </xsl:variable>
101
+
102
+ <xsl:variable name="units">
103
+ <xsl:value-of select="substring($length, string-length($magnitude)+1)"/>
104
+ </xsl:variable>
105
+
106
+ <xsl:variable name="inches">
107
+ <xsl:choose>
108
+ <xsl:when test="$units = 'px'">
109
+ <xsl:value-of select="$magnitude div $pixels.per.inch"/>
110
+ </xsl:when>
111
+ <xsl:when test="$units = 'em'">
112
+ <xsl:value-of select="$magnitude div $em.size"/>
113
+ </xsl:when>
114
+ <xsl:otherwise>
115
+ <xsl:message>
116
+ <xsl:text>Unrecognized unit of measure: </xsl:text>
117
+ <xsl:value-of select="$units"></xsl:value-of>
118
+ <xsl:text>.</xsl:text>
119
+ </xsl:message>
120
+ </xsl:otherwise>
121
+ </xsl:choose>
122
+ </xsl:variable>
123
+
124
+ <xsl:value-of select="$inches * $emus.per.inch"/>
125
+ </xsl:template>
126
+
127
+ <!-- template as function used to get the width or height of an image in points. -->
128
+ <xsl:template name="image-dimention">
129
+ <xsl:param name="style" />
130
+ <xsl:param name="data-value" />
131
+ <xsl:param name="type" />
132
+
133
+ <xsl:variable name="size">
134
+ <xsl:choose>
135
+ <xsl:when test="string-length($data-value) > 0">
136
+ <xsl:value-of select="$data-value" />
137
+ </xsl:when>
138
+ <xsl:when test="contains($style, concat($type,':'))">
139
+ <xsl:value-of select="translate(str:tokenize(substring-after($style, concat($type,':')), ';')[1],'&#x20;&#x9;&#xD;&#xA;','')" />
140
+ </xsl:when>
141
+ <xsl:otherwise>1</xsl:otherwise>
142
+ </xsl:choose>
143
+ </xsl:variable>
144
+ <xsl:call-template name="length-in-emus">
145
+ <xsl:with-param name="length" select="$size"/>
146
+ </xsl:call-template>
147
+ </xsl:template>
148
+ </xsl:stylesheet>
@@ -0,0 +1,129 @@
1
+ <xsl:stylesheet xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
2
+ xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main"
3
+ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
4
+ xmlns:mv="urn:schemas-microsoft-com:mac:vml"
5
+ xmlns:o="urn:schemas-microsoft-com:office:office"
6
+ xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
7
+ xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
8
+ xmlns:v="urn:schemas-microsoft-com:vml"
9
+ xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
10
+ xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
11
+ xmlns:w10="urn:schemas-microsoft-com:office:word"
12
+ xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
13
+ xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
14
+ xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
15
+ xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
16
+ xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
17
+ xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
18
+ xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
19
+ xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
20
+ xmlns:a14="http://schemas.microsoft.com/office/drawing/2010/main"
21
+ xmlns:pic="http://schemas.openxmlformats.org/drawingml/2006/picture"
22
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
23
+ xmlns:WX="http://schemas.microsoft.com/office/word/2003/auxHint"
24
+ xmlns:aml="http://schemas.microsoft.com/aml/2001/core"
25
+ xmlns:pkg="http://schemas.microsoft.com/office/2006/xmlPackage"
26
+ xmlns:msxsl="urn:schemas-microsoft-com:xslt"
27
+ xmlns:ext="http://www.xmllab.net/wordml2html/ext"
28
+ xmlns:java="http://xml.apache.org/xalan/java"
29
+ xmlns:str="http://exslt.org/strings"
30
+ xmlns:func="http://exslt.org/functions"
31
+ xmlns:fn="http://www.w3.org/2005/xpath-functions"
32
+ mc:Ignorable="w14 w15 wp14 a14"
33
+ version="1.0"
34
+ exclude-result-prefixes="java msxsl ext w o v WX aml w10"
35
+ extension-element-prefixes="func">
36
+
37
+ <xsl:include href="./image_functions.xslt"/>
38
+
39
+ <xsl:template match="img|body/img" name="image">
40
+ <w:drawing>
41
+ <wp:inline distT="0" distB="0" distL="0" distR="0">
42
+ <wp:extent>
43
+ <xsl:call-template name="image-dimention-attributes"/>
44
+ </wp:extent>
45
+ <wp:effectExtent l="0" t="0" r="0" b="0"/>
46
+ <wp:docPr>
47
+ <xsl:attribute name="id"><xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
48
+ <xsl:attribute name="name">Picture <xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
49
+ </wp:docPr>
50
+ <wp:cNvGraphicFramePr>
51
+ <a:graphicFrameLocks noChangeAspect="1"/>
52
+ </wp:cNvGraphicFramePr>
53
+ <a:graphic>
54
+ <a:graphicData uri="http://schemas.openxmlformats.org/drawingml/2006/picture">
55
+ <pic:pic>
56
+ <pic:nvPicPr>
57
+ <pic:cNvPr>
58
+ <xsl:attribute name="id"><xsl:value-of select="count(preceding::img)+1" /></xsl:attribute>
59
+ <xsl:attribute name="title"><xsl:value-of select="@alt" /></xsl:attribute>
60
+ <xsl:attribute name="name"><xsl:call-template name="image-name">
61
+ <xsl:with-param name="source" select="@src"/>
62
+ <xsl:with-param name="data-filename" select="@data-filename"/>
63
+ </xsl:call-template></xsl:attribute>
64
+ </pic:cNvPr>
65
+ <pic:cNvPicPr/>
66
+ </pic:nvPicPr>
67
+ <pic:blipFill>
68
+ <a:blip>
69
+ <xsl:attribute name="r:embed"><xsl:call-template name="relationship-id"/></xsl:attribute>
70
+ <a:extLst>
71
+ <a:ext uri="{{28A0092B-C50C-407E-A947-70E740481C1C}}">
72
+ <a14:useLocalDpi val="0"/>
73
+ </a:ext>
74
+ </a:extLst>
75
+ </a:blip>
76
+ <a:stretch>
77
+ <a:fillRect/>
78
+ </a:stretch>
79
+ </pic:blipFill>
80
+ <pic:spPr>
81
+ <a:xfrm>
82
+ <a:off x="0" y="0"/>
83
+ <a:ext>
84
+ <xsl:call-template name="image-dimention-attributes"/>
85
+ </a:ext>
86
+ </a:xfrm>
87
+ <a:prstGeom prst="rect">
88
+ <a:avLst/>
89
+ </a:prstGeom>
90
+ </pic:spPr>
91
+ </pic:pic>
92
+ </a:graphicData>
93
+ </a:graphic>
94
+ </wp:inline>
95
+ </w:drawing>
96
+ </xsl:template>
97
+
98
+ <!--
99
+ A style specifiying the width and height is required to render an image correctly in word.
100
+ Styles can be provided either via data attributes:
101
+ img src="pathtosomeimage" data-width="200px" data-height="250px"
102
+
103
+ or via the html style attribute
104
+ img src="pathtosomeimage" style="width:150px;height:200px"
105
+
106
+ If both a style and data attributes are provided then data attributes take president.
107
+ e.g.
108
+ img src="pathtosomeimage" data-width="200em" style="width:150px;height:200px"
109
+ becomes: width:200em;height:200px
110
+
111
+ Note: All sizes must be in pixles or em
112
+ -->
113
+ <xsl:template name="image-dimention-attributes">
114
+ <xsl:attribute name="cx">
115
+ <xsl:call-template name="image-dimention">
116
+ <xsl:with-param name="style" select="@style" />
117
+ <xsl:with-param name="data-value" select="@data-width" />
118
+ <xsl:with-param name="type" select="'width'" />
119
+ </xsl:call-template>
120
+ </xsl:attribute>
121
+ <xsl:attribute name="cy">
122
+ <xsl:call-template name="image-dimention">
123
+ <xsl:with-param name="style" select="@style" />
124
+ <xsl:with-param name="data-value" select="@data-height" />
125
+ <xsl:with-param name="type" select="'height'" />
126
+ </xsl:call-template>
127
+ </xsl:attribute>
128
+ </xsl:template>
129
+ </xsl:stylesheet>
@@ -0,0 +1,40 @@
1
+ <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2
+ <xsl:output encoding="utf-8" omit-xml-declaration="yes" indent="yes" />
3
+
4
+ <xsl:strip-space elements="*"/>
5
+
6
+ <xsl:template match="node()|@*">
7
+ <xsl:copy>
8
+ <xsl:apply-templates select="@*|node()[1]"/>
9
+ </xsl:copy>
10
+ <xsl:apply-templates select="following-sibling::node()[1]"/>
11
+ </xsl:template>
12
+
13
+ <!-- get first inline element of a sequence or text having block element siblings... -->
14
+ <xsl:template match="node()[self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()][parent::div|parent::li|parent::td]">
15
+ <div>
16
+ <xsl:attribute name="class"><xsl:value-of select="../@class"/></xsl:attribute>
17
+ <xsl:attribute name="style"><xsl:value-of select="../@style"/></xsl:attribute>
18
+ <xsl:call-template name="inlineElement"/>
19
+ </div>
20
+ <xsl:apply-templates select="following-sibling::node()[not((self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text())[parent::div|parent::li|parent::td])][1]"/>
21
+ </xsl:template>
22
+
23
+ <!-- get following inline elements... -->
24
+ <xsl:template match="
25
+ a[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
26
+ |b[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
27
+ |i[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
28
+ |s[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
29
+ |span[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
30
+ |sub[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
31
+ |sup[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
32
+ |u[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]
33
+ |text()[preceding-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]]"
34
+ name="inlineElement">
35
+ <xsl:copy>
36
+ <xsl:apply-templates select="@*|node()[1]"/>
37
+ </xsl:copy>
38
+ <xsl:apply-templates select="following-sibling::node()[1][self::a|self::b|self::i|self::s|self::span|self::sub|self::sup|self::u|self::text()]"/>
39
+ </xsl:template>
40
+ </xsl:stylesheet>