VirtualBox

source: vbox/trunk/doc/manual/dita-refentry-link-replacement-xsl-gen.xsl

Last change on this file was 99014, checked in by vboxsync, 14 months ago

manual: Use the UserManual.ditamap instead of UserManual.xml to generate xslt for link replacement in manual pages. bugref:10302

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1<?xml version="1.0"?>
2<!--
3 dita-refentry-link-replacement-xsl-gen.xsl:
4 XSLT stylesheet for generate a stylesheet that replaces links
5 to the user manual in the manpages.
6-->
7<!--
8 Copyright (C) 2006-2023 Oracle and/or its affiliates.
9
10 This file is part of VirtualBox base platform packages, as
11 available from https://www.virtualbox.org.
12
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation, in version 3 of the
16 License.
17
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, see <https://www.gnu.org/licenses>.
25
26 SPDX-License-Identifier: GPL-3.0-only
27-->
28
29<xsl:stylesheet
30 version="1.0"
31 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
32 >
33
34 <xsl:output method="text" version="1.0" encoding="utf-8" indent="yes"/>
35 <xsl:strip-space elements="*"/>
36
37<xsl:param name="g_sMode" select="not-specified"/>
38
39 <!-- Translatable strings -->
40 <xsl:variable name="sChapter" select="'chapter'"/>
41 <xsl:variable name="sSection" select="'section'"/>
42 <xsl:variable name="sInChapter" select="'in chapter'"/>
43 <xsl:variable name="sPreface" select="'in the preface to the user manual'"/>
44 <xsl:variable name="sOfManual" select="'of the user manual'"/>
45 <xsl:variable name="sInManual" select="'in the user manual'"/>
46
47
48<!-- Default operation is to supress output -->
49<xsl:template match="node()|@*">
50 <xsl:apply-templates/>
51</xsl:template>
52
53
54<!--
55Output header and footer.
56-->
57<xsl:template match="/">
58 <xsl:if test="$g_sMode = 'first'">
59 <xsl:text>&lt;?xml version="1.0"?&gt;
60&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" &gt;
61&lt;xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" /&gt;
62&lt;xsl:template match="node()|@*"&gt;
63 &lt;xsl:copy&gt;
64 &lt;xsl:apply-templates select="node()|@*"/&gt;
65 &lt;/xsl:copy&gt;
66&lt;/xsl:template&gt;
67
68</xsl:text>
69 </xsl:if>
70 <xsl:apply-templates/>
71 <xsl:if test="$g_sMode = 'last'">
72 <xsl:text>
73&lt;/xsl:stylesheet&gt;
74</xsl:text>
75 </xsl:if>
76</xsl:template>
77
78
79<!--
80Produce the transformation templates:
81-->
82<xsl:template match="chapter/topic[@id]/title">
83 <xsl:text>
84&lt;xsl:template match="xref[@linkend='</xsl:text>
85 <xsl:value-of select="../@id"/><xsl:text>']"&gt;
86 &lt;xsl:text&gt;</xsl:text><xsl:value-of select="$sChapter"/><xsl:text> </xsl:text>
87 <xsl:value-of select="count(../preceding-sibling::chapter) + 1"/><xsl:text> &quot;</xsl:text>
88 <xsl:value-of select="normalize-space()"/>
89 <xsl:text>&quot; </xsl:text><xsl:value-of select="$sInManual"/><xsl:text>&lt;/xsl:text&gt;
90&lt;/xsl:template&gt;
91</xsl:text>
92 <xsl:apply-templates/>
93</xsl:template>
94
95<xsl:template match="*/topicwrap/topic[@id]/title">
96 <xsl:variable name="iDepth" select="count(ancestor-or-self::topicwrap)" />
97
98 <xsl:text>&lt;xsl:template match="xref[@linkend='</xsl:text>
99 <xsl:value-of select="../@id"/><xsl:text>']"&gt;
100 &lt;xsl:text&gt;</xsl:text><xsl:value-of select="$sSection"/>
101 <xsl:text> &quot;</xsl:text>
102 <xsl:value-of select="normalize-space()"/><xsl:text>&quot; </xsl:text>
103
104 <!-- Currently DITA only does chapter numbering, which mean the poor buggers
105 need to do text searches for the (sub*)section titles. So we emit a
106 'in chapter xx of the user manual' to help out. -->
107 <xsl:choose>
108 <xsl:when test="ancestor-or-self::chapter">
109 <xsl:value-of select="$sInChapter"/><xsl:text> </xsl:text>
110 <xsl:choose>
111 <xsl:when test="$iDepth = 1">
112 <xsl:value-of select="count(../../preceding-sibling::chapter) + 1" />
113 </xsl:when>
114 <xsl:when test="$iDepth = 2">
115 <xsl:value-of select="count(../../../preceding-sibling::chapter) + 1" />
116 </xsl:when>
117 <xsl:when test="$iDepth = 3">
118 <xsl:value-of select="count(../../../../preceding-sibling::chapter) + 1" />
119 </xsl:when>
120 <xsl:when test="$iDepth = 4">
121 <xsl:value-of select="count(../../../../../preceding-sibling::chapter) + 1" />
122 </xsl:when>
123 <xsl:when test="$iDepth = 5">
124 <xsl:value-of select="count(../../../../../../preceding-sibling::chapter) + 1" />
125 </xsl:when>
126 <xsl:otherwise>
127 <xsl:message terminate="yes">Too deep topic nesting! <xsl:call-template name="get-node-path"/></xsl:message>
128 </xsl:otherwise>
129 </xsl:choose>
130 <xsl:text> </xsl:text>
131 <xsl:value-of select="$sOfManual"/>
132 </xsl:when>
133
134 <xsl:when test="ancestor-or-self::prefacewrap">
135 <xsl:if test="$iDepth != 1">
136 <xsl:message terminate="yes">Too deep preface topic nesting! <xsl:call-template name="get-node-path"/></xsl:message>
137 </xsl:if>
138 <xsl:value-of select="$sPreface"/><xsl:text> </xsl:text>
139 </xsl:when>
140
141 <xsl:otherwise>
142 <xsl:message terminate="yes">Unexpected topicwrap parent: <xsl:call-template name="get-node-path"/></xsl:message>
143 </xsl:otherwise>
144 </xsl:choose>
145 <xsl:text>&lt;/xsl:text&gt;
146&lt;/xsl:template&gt;
147</xsl:text>
148 <xsl:apply-templates/>
149</xsl:template>
150
151<!--
152 Debug/Diagnostics: Return the path to the specified node (by default the current).
153 -->
154<xsl:template name="get-node-path">
155 <xsl:param name="Node" select="."/>
156 <xsl:for-each select="$Node">
157 <xsl:for-each select="ancestor-or-self::node()">
158 <xsl:choose>
159 <xsl:when test="name(.) = ''">
160 <xsl:text>text()</xsl:text>
161 </xsl:when>
162 <xsl:otherwise>
163 <xsl:value-of select="concat('/', name(.))"/>
164 <xsl:choose>
165 <xsl:when test="@id">
166 <xsl:text>[@id=</xsl:text>
167 <xsl:value-of select="@id"/>
168 <xsl:text>]</xsl:text>
169 </xsl:when>
170 <xsl:when test="position() > 1">
171 <xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]</xsl:text>
172 </xsl:when>
173 </xsl:choose>
174 </xsl:otherwise>
175 </xsl:choose>
176 </xsl:for-each>
177 </xsl:for-each>
178</xsl:template>
179
180</xsl:stylesheet>
181
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use