forked from williamsjj/markdown2manning_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocbook2manning.xslt
140 lines (116 loc) · 3.52 KB
/
docbook2manning.xslt
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--Remove All "article" tags while leaving children-->
<xsl:template match="article">
<xsl:apply-templates select="node()"/>
</xsl:template>
<!--Remove "articleinfo" tags and kill children-->
<xsl:template match="articleinfo">
<!--Remove Tag-->
</xsl:template>
<!--Convert outer "section" tag to "chapter"-->
<xsl:template match="/article/section">
<book xmlns="http://www.manning.com/schemas/book" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://www.manning.com/schemas/book">
<bookinfo><title/><author><firstname /><surname /></author></bookinfo>
<chapter>
<xsl:attribute name="label"><xsl:value-of select="$chapternum"/></xsl:attribute>
<xsl:apply-templates select="node()"/>
</chapter>
</book>
</xsl:template>
<!-- Copy section, but not its attributes -->
<xsl:template match="section">
<xsl:copy>
<xsl:apply-templates select="*|node()"/>
</xsl:copy>
</xsl:template>
<!--Convert "textobject" to "caption"-->
<xsl:template match="textobject">
<caption><xsl:apply-templates select="node()"/></caption>
</xsl:template>
<!--Convert "literal" to "code"-->
<xsl:template match="literal">
<code><xsl:apply-templates select="node()"/></code>
</xsl:template>
<!--Convert "phrase" to "para"-->
<xsl:template match="phrase">
<para><xsl:apply-templates select="node()"/></para>
</xsl:template>
<!--Remove "numeration" attribute from "orderedlist" elements-->
<xsl:template match="@numeration" />
<xsl:template match="@numeration" />
<!--Convert "screen" to "informalexample"-->
<xsl:template match="screen[not(@*)]">
<informalexample>
<programlisting>
<xsl:apply-templates select="node()"/>
</programlisting>
</informalexample>
</xsl:template>
<!--Convert "screen" to "example"-->
<xsl:template match="screen[@language]">
<example>
<programlisting>
<xsl:apply-templates select="node()"/>
</programlisting>
</example>
</xsl:template>
<!-- Convert "role" attributes with value "strong" to value "bold"-->
<xsl:template match="@role[.='strong']">
<xsl:attribute name="role">
<xsl:text>bold</xsl:text>
</xsl:attribute>
</xsl:template>
<!-- Remove "float" attribute -->
<xsl:template match="@float" />
<!--Convert "informaltable" to "table"-->
<xsl:template match="informaltable">
<table>
<title></title>
<xsl:apply-templates select="node()"/>
</table>
</xsl:template>
<!-- Remove "table/col" elements -->
<xsl:template match="informaltable/col" />
<!--Convert "table/caption" to "table/title"-->
<xsl:template match="table/caption">
<title>
<xsl:apply-templates select="node()"/>
</title>
</xsl:template>
<!-- Remove "table/col" elements -->
<xsl:template match="table/col" />
<!--Convert "thead/tr" to "thead/row"-->
<xsl:template match="thead/tr">
<row>
<xsl:apply-templates select="node()"/>
</row>
</xsl:template>
<!--Convert "tbody/tr" to "tbody/row"-->
<xsl:template match="tbody/tr">
<row>
<xsl:apply-templates select="node()"/>
</row>
</xsl:template>
<!--Convert "tr/th" to "tr/entry"-->
<xsl:template match="tr/th">
<entry>
<para>
<xsl:apply-templates select="node()"/>
</para>
</entry>
</xsl:template>
<!--Convert "tr/td" to "tr/entry"-->
<xsl:template match="tr/td">
<entry>
<para>
<xsl:apply-templates select="node()"/>
</para>
</entry>
</xsl:template>
</xsl:stylesheet>