Skip to content

Commit 0b4d914

Browse files
committed
Added XSLT files fodt to json/xml for use with Saxon/C Python API.
1 parent c532c63 commit 0b4d914

File tree

4 files changed

+482
-0
lines changed

4 files changed

+482
-0
lines changed
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
5+
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
6+
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
7+
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
8+
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
9+
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
10+
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
11+
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
12+
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
13+
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
14+
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
15+
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
16+
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
17+
xmlns:math="http://www.w3.org/1998/Math/MathML"
18+
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
19+
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
20+
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
21+
xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
22+
xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
23+
xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xmlns:rpt="http://openoffice.org/2005/report"
26+
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
27+
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
28+
xmlns:officeooo="http://openoffice.org/2009/office"
29+
xmlns:tableooo="http://openoffice.org/2009/table"
30+
xmlns:drawooo="http://openoffice.org/2010/draw"
31+
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
32+
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
33+
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
34+
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
35+
xmlns:css3t="http://www.w3.org/TR/css3-text/" exclude-result-prefixes="#all" version="3.0">
36+
<xsl:output indent="yes" method="text"/>
37+
<xsl:mode on-no-match="shallow-copy"/>
38+
39+
40+
41+
<xsl:variable name="auto-styles" select="/office:document/office:automatic-styles"/>
42+
43+
<xsl:template match="/office:document">
44+
{
45+
<xsl:variable name="meta" >
46+
<xsl:text>"metadata": {
47+
"title": "</xsl:text><xsl:value-of select="office:meta/dc:title"/><xsl:text>",</xsl:text>
48+
<xsl:text>
49+
"subject": "</xsl:text><xsl:value-of select="office:meta/dc:subject"/><xsl:text>",</xsl:text>
50+
<xsl:text>
51+
"description": "</xsl:text><xsl:value-of select="office:meta/dc:description"/><xsl:text>",</xsl:text>
52+
<xsl:text>
53+
"keywords": [</xsl:text>
54+
<xsl:for-each select="office:meta/meta:keyword">
55+
<xsl:choose>
56+
<xsl:when test="position() != last()">
57+
"<xsl:value-of select="."/>",
58+
</xsl:when>
59+
<xsl:otherwise>
60+
"<xsl:value-of select="."/>"
61+
</xsl:otherwise>
62+
</xsl:choose>
63+
</xsl:for-each>
64+
<xsl:text>]</xsl:text>
65+
<xsl:text>},</xsl:text>
66+
</xsl:variable>
67+
<xsl:value-of select="$meta"/>
68+
<xsl:text>
69+
"document": </xsl:text>
70+
[
71+
<xsl:apply-templates select="office:body/office:text/child::*"/>
72+
]
73+
}
74+
</xsl:template>
75+
76+
<!-- Empty Nodes -->
77+
<xsl:template match="office:forms"/>
78+
<xsl:template match="text:sequence-decls"/>
79+
80+
<xsl:template match="*">
81+
<xsl:variable name="elementName" select="local-name(.)"/>
82+
<xsl:choose>
83+
<xsl:when test="matches($elementName, '^(h|p|span|table|table-cell|table-row|list|list-item)$')">
84+
<xsl:element name="{$elementName}">
85+
{
86+
"type": "<xsl:value-of select="$elementName"/>",
87+
"content": [
88+
<xsl:apply-templates/>
89+
],
90+
"nested": <xsl:value-of select="has-children()"/>,
91+
"has_elements": <xsl:value-of select="boolean(child::*)"/>
92+
}
93+
<xsl:choose>
94+
95+
<xsl:when test="(not(position() = last()) or following-sibling::*)">
96+
<xsl:text>,</xsl:text>
97+
</xsl:when>
98+
<xsl:otherwise/>
99+
</xsl:choose>
100+
101+
</xsl:element>
102+
</xsl:when>
103+
<xsl:otherwise/>
104+
105+
106+
</xsl:choose>
107+
</xsl:template>
108+
109+
<xsl:template match="text()">
110+
<xsl:choose>
111+
<xsl:when test="not(boolean(normalize-space(.) = ''))">
112+
<xsl:text>{
113+
"type": "text",
114+
"content": "</xsl:text><xsl:value-of select="replace(normalize-space(.),'&quot;','”')"/>"
115+
<!--,
116+
"empty": <xsl:value-of select="boolean(normalize-space(.) = '')"/>
117+
-->
118+
<xsl:text>
119+
}
120+
</xsl:text>
121+
<xsl:if test="following-sibling::*">
122+
<xsl:text>,</xsl:text>
123+
</xsl:if>
124+
</xsl:when>
125+
<xsl:when test="position() = last()">
126+
{
127+
"skip": true,
128+
"type": "trailing_whitespace"
129+
}
130+
</xsl:when>
131+
<xsl:otherwise/>
132+
</xsl:choose>
133+
134+
135+
</xsl:template>
136+
137+
</xsl:stylesheet>
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
5+
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
6+
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
7+
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
8+
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
9+
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
10+
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
11+
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
12+
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
13+
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
14+
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
15+
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
16+
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
17+
xmlns:math="http://www.w3.org/1998/Math/MathML"
18+
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
19+
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
20+
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
21+
xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
22+
xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
23+
xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xmlns:rpt="http://openoffice.org/2005/report"
26+
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
27+
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
28+
xmlns:officeooo="http://openoffice.org/2009/office"
29+
xmlns:tableooo="http://openoffice.org/2009/table"
30+
xmlns:drawooo="http://openoffice.org/2010/draw"
31+
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
32+
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
33+
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
34+
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
35+
xmlns:css3t="http://www.w3.org/TR/css3-text/" exclude-result-prefixes="#all" version="3.0">
36+
<xsl:output indent="yes" method="text"/>
37+
<xsl:mode on-no-match="shallow-copy"/>
38+
39+
40+
<xsl:template match="/office:document">
41+
{
42+
<xsl:variable name="meta" >
43+
<xsl:text>"metadata": {
44+
"title": "</xsl:text><xsl:value-of select="office:meta/dc:title"/><xsl:text>",</xsl:text>
45+
<xsl:text>
46+
"subject": "</xsl:text><xsl:value-of select="office:meta/dc:subject"/><xsl:text>",</xsl:text>
47+
<xsl:text>
48+
"description": "</xsl:text><xsl:value-of select="office:meta/dc:description"/><xsl:text>",</xsl:text>
49+
<xsl:text>
50+
"keywords": [</xsl:text>
51+
<xsl:for-each select="office:meta/meta:keyword">
52+
<xsl:choose>
53+
<xsl:when test="position() != last()">
54+
"<xsl:value-of select="."/>",
55+
</xsl:when>
56+
<xsl:otherwise>
57+
"<xsl:value-of select="."/>"
58+
</xsl:otherwise>
59+
</xsl:choose>
60+
</xsl:for-each>
61+
<xsl:text>]</xsl:text>
62+
<xsl:text>},</xsl:text>
63+
</xsl:variable>
64+
<xsl:value-of select="$meta"/>
65+
<xsl:text>
66+
"document": </xsl:text>
67+
[
68+
<xsl:apply-templates select="office:body/office:text/child::*"/>
69+
]
70+
}
71+
</xsl:template>
72+
73+
<!-- Empty Nodes -->
74+
<xsl:template match="office:forms"/>
75+
<xsl:template match="text:sequence-decls"/>
76+
77+
<xsl:template match="*">
78+
<xsl:variable name="elementName" select="local-name(.)"/>
79+
<xsl:variable name="serial-params">
80+
<output:serialization-parameters>
81+
<output:omit-xml-declaration value="yes" />
82+
</output:serialization-parameters>
83+
</xsl:variable>
84+
<xsl:choose>
85+
<xsl:when test="matches($elementName, '^(h|p|table-cell|list-item)$')">
86+
<xsl:element name="{$elementName}">
87+
{
88+
"type": "<xsl:value-of select="$elementName"/>",
89+
"text": "<xsl:value-of select="replace(normalize-space(.),'&quot;','”')"/>"
90+
<!-- ,
91+
"raw": "<xsl:value-of select="replace(normalize-space(serialize(., $serial-params/*)),'&quot;','”')"/>"
92+
-->
93+
}
94+
<xsl:choose>
95+
96+
<xsl:when test="(not(position() = last()) or following-sibling::*)">
97+
<xsl:text>,</xsl:text>
98+
</xsl:when>
99+
<xsl:otherwise/>
100+
</xsl:choose>
101+
102+
</xsl:element>
103+
</xsl:when>
104+
<xsl:otherwise>
105+
<xsl:apply-templates/>
106+
</xsl:otherwise>
107+
108+
109+
</xsl:choose>
110+
</xsl:template>
111+
112+
113+
</xsl:stylesheet>
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:output="http://www.w3.org/2010/xslt-xquery-serialization"
5+
xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
6+
xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
7+
xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
8+
xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
9+
xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
10+
xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
11+
xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/"
12+
xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
13+
xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
14+
xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
15+
xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
16+
xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
17+
xmlns:math="http://www.w3.org/1998/Math/MathML"
18+
xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
19+
xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
20+
xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
21+
xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer"
22+
xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events"
23+
xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
24+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25+
xmlns:rpt="http://openoffice.org/2005/report"
26+
xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2"
27+
xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#"
28+
xmlns:officeooo="http://openoffice.org/2009/office"
29+
xmlns:tableooo="http://openoffice.org/2009/table"
30+
xmlns:drawooo="http://openoffice.org/2010/draw"
31+
xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0"
32+
xmlns:loext="urn:org:documentfoundation:names:experimental:office:xmlns:loext:1.0"
33+
xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0"
34+
xmlns:formx="urn:openoffice:names:experimental:ooxml-odf-interop:xmlns:form:1.0"
35+
xmlns:css3t="http://www.w3.org/TR/css3-text/" exclude-result-prefixes="#all" version="3.0">
36+
<xsl:output indent="yes" method="xml"/>
37+
<xsl:mode on-no-match="shallow-copy"/>
38+
39+
40+
41+
<xsl:variable name="auto-styles" select="/office:document/office:automatic-styles"/>
42+
43+
<xsl:template match="/office:document">
44+
<xsl:variable name="meta" >
45+
<metadata>
46+
<title>
47+
<xsl:value-of select="office:meta/dc:title"/>
48+
</title>
49+
<subject>
50+
<xsl:value-of select="office:meta/dc:subject"/>
51+
</subject>
52+
<description>
53+
<xsl:value-of select="office:meta/dc:description"/>
54+
</description>
55+
<keywords>
56+
<xsl:for-each select="office:meta/meta:keyword">
57+
<keyword>
58+
<xsl:value-of select="."/>
59+
</keyword>
60+
</xsl:for-each>
61+
</keywords>
62+
</metadata>
63+
</xsl:variable>
64+
<document>
65+
<xsl:copy-of select="$meta"/>
66+
<text>
67+
<xsl:apply-templates select="office:body/office:text/child::*"/>
68+
</text>
69+
</document>
70+
</xsl:template>
71+
72+
<!-- Empty Nodes -->
73+
<xsl:template match="office:forms"/>
74+
<xsl:template match="text:sequence-decls"/>
75+
76+
<xsl:template match="*">
77+
<xsl:variable name="elementName" select="local-name(.)"/>
78+
<xsl:element name="{$elementName}">
79+
<xsl:apply-templates/>
80+
</xsl:element>
81+
</xsl:template>
82+
83+
</xsl:stylesheet>

0 commit comments

Comments
 (0)