-
Notifications
You must be signed in to change notification settings - Fork 2
/
xmltojson.xsl
55 lines (47 loc) · 1.89 KB
/
xmltojson.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
xmlns:rels="http://schemas.openxmlformats.org/package/2006/relationships"
xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
exclude-result-prefixes="*">
<xsl:output method="xml" indent="yes"
encoding="UTF-8"
/>
<xsl:template match="/">
doc = {
<xsl:apply-templates />
}
</xsl:template>
<!-- document properties .e.g title -->
<xsl:template match="head">
properties : {
<xsl:apply-templates/>
},
</xsl:template>
<xsl:template match="head/*"><xsl:value-of select="local-name()"/>: '<xsl:value-of select="."/>',</xsl:template>
<xsl:template match="body">
items : [
<xsl:apply-templates/>
],
</xsl:template>
<xsl:template match="toc">
{
type : 'toc',
items : [
<xsl:apply-templates/>
]
},
</xsl:template>
<xsl:template match="item">{
type : '<xsl:value-of select="@type"/>',
style : '<xsl:value-of select="@style"/>',
content : '<xsl:copy-of select="content"/>'
},</xsl:template>
<xsl:template match="text()"><xsl:value-of select="translate(.,'�','')"/></xsl:template>
</xsl:stylesheet>