-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhtml_to_akn.xsl
92 lines (72 loc) · 2.1 KB
/
html_to_akn.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.akomantoso.org/2.0"
exclude-result-prefixes="html">
<xsl:output method="xml" />
<xsl:template match="html:ul | html:li">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="node()" />
</xsl:element>
</xsl:template>
<!-- tables -->
<xsl:template match="html:table">
<table>
<xsl:apply-templates select="@id | .//html:tr" />
</table>
</xsl:template>
<xsl:template match="html:tr">
<tr>
<xsl:apply-templates select="node()" />
</tr>
</xsl:template>
<xsl:template match="html:td | html:th">
<xsl:element name="{local-name(.)}">
<xsl:apply-templates select="@colspan | @rowspan" />
<p>
<xsl:for-each select="node()">
<xsl:choose>
<xsl:when test="name(.) = 'p'">
<!-- ignore p (we already have one) and do children -->
<xsl:apply-templates select="node()"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</p>
</xsl:element>
</xsl:template>
<!-- elements -->
<xsl:template match="html:p | html:div">
<p>
<xsl:apply-templates />
</p>
</xsl:template>
<xsl:template match="html:br">
<eol/>
</xsl:template>
<xsl:template match="html:blockquote">
<p>
<remark status="editorial">
<xsl:apply-templates select=".//text()" />
</remark>
</p>
</xsl:template>
<!-- attributes -->
<xsl:template match="@id | @colspan | @rowspan">
<xsl:attribute name="{name(.)}"><xsl:value-of select="." /></xsl:attribute>
</xsl:template>
<!-- text -->
<xsl:template match="text()">
<xsl:value-of select="."/>
</xsl:template>
<!-- general matching -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates select="node()" />
</xsl:copy>
</xsl:template>
</xsl:stylesheet>