|
| 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(.),'"','”')"/>" |
| 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> |
0 commit comments