[77354] | 1 | <?xml version="1.0"?>
|
---|
| 2 | <!--
|
---|
[99014] | 3 | dita-refentry-link-replacement-xsl-gen.xsl:
|
---|
[77354] | 4 | XSLT stylesheet for generate a stylesheet that replaces links
|
---|
| 5 | to the user manual in the manpages.
|
---|
[96300] | 6 | -->
|
---|
| 7 | <!--
|
---|
[98103] | 8 | Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[77354] | 9 |
|
---|
[96407] | 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
|
---|
[77354] | 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 |
|
---|
[92084] | 37 | <xsl:param name="g_sMode" select="not-specified"/>
|
---|
[77354] | 38 |
|
---|
[92824] | 39 | <!-- Translatable strings -->
|
---|
[99014] | 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'"/>
|
---|
[92824] | 46 |
|
---|
| 47 |
|
---|
[77354] | 48 | <!-- Default operation is to supress output -->
|
---|
| 49 | <xsl:template match="node()|@*">
|
---|
| 50 | <xsl:apply-templates/>
|
---|
| 51 | </xsl:template>
|
---|
| 52 |
|
---|
| 53 |
|
---|
| 54 | <!--
|
---|
| 55 | Output header and footer.
|
---|
| 56 | -->
|
---|
| 57 | <xsl:template match="/">
|
---|
[92084] | 58 | <xsl:if test="$g_sMode = 'first'">
|
---|
| 59 | <xsl:text><?xml version="1.0"?>
|
---|
[77354] | 60 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
|
---|
| 61 | <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes" />
|
---|
| 62 | <xsl:template match="node()|@*">
|
---|
| 63 | <xsl:copy>
|
---|
| 64 | <xsl:apply-templates select="node()|@*"/>
|
---|
| 65 | </xsl:copy>
|
---|
| 66 | </xsl:template>
|
---|
| 67 |
|
---|
| 68 | </xsl:text>
|
---|
[92084] | 69 | </xsl:if>
|
---|
[77354] | 70 | <xsl:apply-templates/>
|
---|
[92084] | 71 | <xsl:if test="$g_sMode = 'last'">
|
---|
| 72 | <xsl:text>
|
---|
[77354] | 73 | </xsl:stylesheet>
|
---|
| 74 | </xsl:text>
|
---|
[92084] | 75 | </xsl:if>
|
---|
[77354] | 76 | </xsl:template>
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | <!--
|
---|
| 80 | Produce the transformation templates:
|
---|
| 81 | -->
|
---|
[99014] | 82 | <xsl:template match="chapter/topic[@id]/title">
|
---|
[77354] | 83 | <xsl:text>
|
---|
| 84 | <xsl:template match="xref[@linkend='</xsl:text>
|
---|
| 85 | <xsl:value-of select="../@id"/><xsl:text>']">
|
---|
[92824] | 86 | <xsl:text></xsl:text><xsl:value-of select="$sChapter"/><xsl:text> </xsl:text>
|
---|
| 87 | <xsl:value-of select="count(../preceding-sibling::chapter) + 1"/><xsl:text> "</xsl:text>
|
---|
[77354] | 88 | <xsl:value-of select="normalize-space()"/>
|
---|
[92824] | 89 | <xsl:text>" </xsl:text><xsl:value-of select="$sInManual"/><xsl:text></xsl:text>
|
---|
[77354] | 90 | </xsl:template>
|
---|
| 91 | </xsl:text>
|
---|
| 92 | <xsl:apply-templates/>
|
---|
| 93 | </xsl:template>
|
---|
| 94 |
|
---|
[99014] | 95 | <xsl:template match="*/topicwrap/topic[@id]/title">
|
---|
| 96 | <xsl:variable name="iDepth" select="count(ancestor-or-self::topicwrap)" />
|
---|
[77354] | 97 |
|
---|
| 98 | <xsl:text><xsl:template match="xref[@linkend='</xsl:text>
|
---|
| 99 | <xsl:value-of select="../@id"/><xsl:text>']">
|
---|
[99014] | 100 | <xsl:text></xsl:text><xsl:value-of select="$sSection"/>
|
---|
[77354] | 101 | <xsl:text> "</xsl:text>
|
---|
[92824] | 102 | <xsl:value-of select="normalize-space()"/><xsl:text>" </xsl:text>
|
---|
[77354] | 103 |
|
---|
[99014] | 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>
|
---|
[77354] | 133 |
|
---|
[99014] | 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>
|
---|
[77354] | 140 |
|
---|
[99014] | 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></xsl:text>
|
---|
[92084] | 146 | </xsl:template>
|
---|
| 147 | </xsl:text>
|
---|
| 148 | <xsl:apply-templates/>
|
---|
| 149 | </xsl:template>
|
---|
| 150 |
|
---|
[77354] | 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 |
|
---|