Release 1.39.0
[boost.git] / Boost_1_39_0 / tools / boostbook / xsl / dtd / dtd2boostbook.xsl
blob38bf815fabd43657bd91d12c467a707eefa2223c
1 <?xml version="1.0" encoding="utf-8"?>
2 <!--
3 Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
5 Distributed under the Boost Software License, Version 1.0.
6 (See accompanying file LICENSE_1_0.txt or copy at
7 http://www.boost.org/LICENSE_1_0.txt)
8 -->
9 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10 version="1.0">
12 <xsl:output method="xml" indent="yes" standalone="yes"/>
14 <xsl:strip-space elements="sequence-group or-group element element-name"/>
16 <xsl:key name="elements" match="element" use="@name"/>
17 <xsl:key name="attributes" match="attlist" use="@name"/>
18 <xsl:key name="attribute-purposes" match="attpurpose" use="@name"/>
20 <xsl:template match="dtd">
21 <section id="reference">
22 <title>Reference</title>
23 <para>
24 <xsl:text>Elements:</xsl:text>
25 <itemizedlist spacing="compact">
26 <xsl:apply-templates select="element" mode="synopsis">
27 <xsl:sort select="@name"/>
28 </xsl:apply-templates>
29 </itemizedlist>
30 </para>
31 <xsl:apply-templates select="element"/>
32 </section>
33 </xsl:template>
35 <!-- Element synopsis -->
36 <xsl:template match="element" mode="synopsis">
37 <listitem>
38 <simpara>
39 <link>
40 <xsl:attribute name="linkend">
41 <xsl:value-of select="concat('boostbook.dtd.',@name)"/>
42 </xsl:attribute>
43 <xsl:text>Element </xsl:text>
44 <sgmltag><xsl:value-of select="@name"/></sgmltag>
45 <xsl:text> - </xsl:text>
46 <xsl:apply-templates select="purpose"/>
47 </link>
48 </simpara>
49 </listitem>
50 </xsl:template>
52 <!-- Elements are transformed into DocBook refentry elements -->
53 <xsl:template match="element">
54 <refentry>
55 <xsl:attribute name="id">
56 <xsl:value-of select="concat('boostbook.dtd.',@name)"/>
57 </xsl:attribute>
59 <refmeta>
60 <refentrytitle>
61 BoostBook element <sgmltag><xsl:value-of select="@name"/></sgmltag>
62 </refentrytitle>
63 <manvolnum>9</manvolnum>
64 </refmeta>
65 <refnamediv>
66 <refname><xsl:value-of select="@name"/></refname>
67 <refpurpose><xsl:apply-templates select="purpose"/></refpurpose>
68 </refnamediv>
69 <refsynopsisdiv>
70 <xsl:value-of select="@name"/><xsl:text> ::= </xsl:text>
71 <xsl:apply-templates select="content-model-expanded"/>
72 </refsynopsisdiv>
73 <xsl:apply-templates select="description"/>
74 <xsl:apply-templates select="key('attributes', @name)"/>
75 </refentry>
76 </xsl:template>
78 <xsl:template match="content-model-expanded">
79 <xsl:apply-templates/>
80 </xsl:template>
82 <!-- Sequences -->
83 <xsl:template match="sequence-group">
84 <xsl:param name="separator" select="''"/>
86 <xsl:if test="preceding-sibling::*">
87 <xsl:value-of select="$separator"/>
88 </xsl:if>
89 <xsl:text>(</xsl:text>
90 <xsl:apply-templates>
91 <xsl:with-param name="separator" select="', '"/>
92 </xsl:apply-templates>
93 <xsl:text>)</xsl:text>
94 <xsl:value-of select="@occurrence"/>
95 </xsl:template>
97 <!-- Alternatives -->
98 <xsl:template match="or-group">
99 <xsl:param name="separator" select="''"/>
101 <xsl:if test="preceding-sibling::*">
102 <xsl:value-of select="$separator"/>
103 </xsl:if>
104 <xsl:text>(</xsl:text>
105 <xsl:apply-templates>
106 <xsl:with-param name="separator" select="'| '"/>
107 </xsl:apply-templates>
108 <xsl:text>)</xsl:text>
109 <xsl:value-of select="@occurrence"/>
110 </xsl:template>
112 <!-- Element references -->
113 <xsl:template match="element-name">
114 <xsl:param name="separator" select="''"/>
116 <xsl:if test="preceding-sibling::*">
117 <xsl:value-of select="$separator"/>
118 </xsl:if>
120 <xsl:variable name="element-node" select="key('elements', @name)"/>
122 <xsl:choose>
123 <xsl:when test="$element-node">
124 <link>
125 <xsl:attribute name="linkend">
126 <xsl:value-of select="concat('boostbook.dtd.',@name)"/>
127 </xsl:attribute>
128 <xsl:value-of select="@name"/>
129 </link>
130 </xsl:when>
131 <xsl:otherwise>
132 <xsl:value-of select="@name"/>
133 </xsl:otherwise>
134 </xsl:choose>
135 <xsl:value-of select="@occurrence"/>
136 </xsl:template>
138 <!-- #PCDATA -->
139 <xsl:template match="pcdata">
140 <xsl:param name="separator" select="''"/>
142 <xsl:if test="preceding-sibling::*">
143 <xsl:value-of select="$separator"/>
144 </xsl:if>
146 <xsl:text>#PCDATA</xsl:text>
147 </xsl:template>
149 <!-- ANY -->
150 <xsl:template match="any">
151 <xsl:text>ANY</xsl:text>
152 </xsl:template>
154 <!-- EMPTY -->
155 <xsl:template match="empty">
156 <xsl:text>EMPTY</xsl:text>
157 </xsl:template>
159 <!-- Just copy anything in a purpose element -->
160 <xsl:template match="purpose">
161 <xsl:copy-of select="text()|*"/>
162 </xsl:template>
164 <!-- Just copy anything in a description element, but place it in a
165 section. -->
166 <xsl:template match="description">
167 <refsection>
168 <title>Description</title>
169 <xsl:copy-of select="text()|*"/>
170 </refsection>
171 </xsl:template>
173 <!-- Attributes -->
174 <xsl:template match="attlist">
175 <refsection>
176 <title>Attributes</title>
178 <informaltable>
179 <tgroup cols="4">
180 <thead>
181 <row>
182 <entry>Name</entry>
183 <entry>Type</entry>
184 <entry>Value</entry>
185 <entry>Purpose</entry>
186 </row>
187 </thead>
188 <tbody>
189 <xsl:apply-templates/>
190 </tbody>
191 </tgroup>
192 </informaltable>
193 </refsection>
194 </xsl:template>
196 <!-- Attribute -->
197 <xsl:template match="attribute">
198 <row>
199 <entry><xsl:value-of select="@name"/></entry>
200 <entry><xsl:value-of select="@type"/></entry>
201 <entry><xsl:value-of select="@value"/></entry>
202 <entry>
203 <xsl:choose>
204 <xsl:when test="purpose">
205 <xsl:apply-templates select="purpose"/>
206 </xsl:when>
207 <xsl:otherwise>
208 <xsl:apply-templates select="key('attribute-purposes', @name)"/>
209 </xsl:otherwise>
210 </xsl:choose>
211 </entry>
212 </row>
213 </xsl:template>
215 <!-- Eat attribute declarations -->
216 <xsl:template match="attdecl"/>
217 </xsl:stylesheet>