commit:     5f5e4cf980ef59f30a7c78477fd13298a53f3bd0
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Wed Mar 10 18:11:41 2021 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Wed Mar 10 18:11:41 2021 +0000
URL:        https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=5f5e4cf9

devbook.xsl: Indent consistently and other whitespace fixes

Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>

 devbook.xsl | 1128 +++++++++++++++++++++++++++++++----------------------------
 1 file changed, 590 insertions(+), 538 deletions(-)

diff --git a/devbook.xsl b/devbook.xsl
index fe93020..abc3853 100644
--- a/devbook.xsl
+++ b/devbook.xsl
@@ -23,354 +23,383 @@
 </xsl:text>
 </xsl:variable>
 
-  <xsl:template match="chapter">
-    <h1 class="first-header">
+<xsl:template match="chapter">
+  <h1 class="first-header">
+    <xsl:apply-templates select="title"/>
+    <a class="permalink" href=""><span class="fa fa-link"/></a>
+  </h1>
+  <xsl:apply-templates select="*[not(self::title)]"/>
+</xsl:template>
+
+<xsl:template match="section|subsection|subsubsection">
+  <xsl:variable name="level" select="2 + number(starts-with(local-name(), 
'sub'))
+                                       + number(starts-with(local-name(), 
'subsub'))"/>
+  <xsl:variable name="anchor">
+    <xsl:call-template name="convert-to-anchor">
+      <xsl:with-param name="data" select="title"/>
+    </xsl:call-template>
+  </xsl:variable>
+  <div class="section">
+    <xsl:element name="h{$level}">
+      <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
       <xsl:apply-templates select="title"/>
-      <a class="permalink" href=""><span class="fa fa-link"/></a>
-    </h1>
+      <a class="permalink" href="#{$anchor}"><span class="fa fa-link"/></a>
+    </xsl:element>
     <xsl:apply-templates select="*[not(self::title)]"/>
-  </xsl:template>
-
-  <xsl:template match="section|subsection|subsubsection">
-    <xsl:variable name="level" select="2 + number(starts-with(local-name(), 
'sub'))
-                                         + number(starts-with(local-name(), 
'subsub'))"/>
-    <xsl:variable name="anchor">
-      <xsl:call-template name="convert-to-anchor">
-        <xsl:with-param name="data" select="title"/>
-      </xsl:call-template>
-    </xsl:variable>
-    <div class="section">
-      <xsl:element name="h{$level}">
-        <xsl:attribute name="id"><xsl:value-of 
select="$anchor"/></xsl:attribute>
-        <xsl:apply-templates select="title"/>
-        <a class="permalink" href="#{$anchor}"><span class="fa fa-link"/></a>
-      </xsl:element>
-      <xsl:apply-templates select="*[not(self::title)]"/>
-    </div>
-  </xsl:template>
-
-  <xsl:template match="body">
-    <xsl:apply-templates/>
-  </xsl:template>
+  </div>
+</xsl:template>
 
-  <xsl:template match="p">
-    <p>
+<xsl:template match="body">
+  <xsl:apply-templates/>
+</xsl:template>
+
+<xsl:template match="p">
+  <p>
     <xsl:apply-templates/>
-    </p>
-  </xsl:template>
+  </p>
+</xsl:template>
 
-  <xsl:template match="pre">
+<xsl:template match="pre">
   <pre><xsl:apply-templates/></pre>
-  </xsl:template>
+</xsl:template>
 
-  <!-- Tables -->
-  <!-- From the Gentoo GuideXML Stylesheet -->
-  <xsl:template match="table">
+<!-- Tables -->
+<!-- From the Gentoo GuideXML Stylesheet -->
+<xsl:template match="table">
   <table class="table"><xsl:apply-templates/></table>
-  </xsl:template>
+</xsl:template>
 
-  <xsl:template match="tr">
+<xsl:template match="tr">
   <tr><xsl:apply-templates/></tr>
-  </xsl:template>
-
-  <!-- Table Item -->
-  <xsl:template match="ti">
-    <td>
-      <xsl:if test="@colspan">
-        <xsl:attribute name="colspan"><xsl:value-of 
select="@colspan"/></xsl:attribute>
-      </xsl:if>
-      <xsl:if test="@rowspan">
-        <xsl:attribute name="rowspan"><xsl:value-of 
select="@rowspan"/></xsl:attribute>
-      </xsl:if>
-      <xsl:if test="@nowrap">
-        <!-- Disable word wrapping for this table item. Usage: <ti 
nowrap="nowrap"> -->
-        <xsl:attribute name="nowrap"><xsl:value-of 
select="@nowrap"/></xsl:attribute>
-      </xsl:if>
-      <xsl:apply-templates/>
-    </td>
-  </xsl:template>
-
-  <!-- Table Heading -->
-  <xsl:template match="th">
-    <th>
-      <xsl:if test="@colspan">
-        <xsl:attribute name="colspan"><xsl:value-of 
select="@colspan"/></xsl:attribute>
-        <!-- Center only when item spans several columns as
-             centering all <th> might disrupt some pages.
-             We might want to use a plain html <th> tag later.
-             Tip: to center a single-cell title, use <th colspan="1">
-          -->
-        <xsl:attribute name="style">text-align:center</xsl:attribute>
-      </xsl:if>
-      <xsl:if test="@rowspan">
-        <xsl:attribute name="rowspan"><xsl:value-of 
select="@rowspan"/></xsl:attribute>
-      </xsl:if>
-        <xsl:apply-templates/>
-    </th>
-  </xsl:template>
-  <!-- End Table Jojo -->
-
-  <!-- FIXME: Handle lang=... -->
-  <xsl:template match="codesample">
-      <xsl:variable name="ctype"><xsl:if test="@lang = 
'ebuild'">Constant</xsl:if></xsl:variable>
-      <xsl:variable name="numbering" select="@numbering"/>
-      <xsl:variable name="lang" select="@lang"/>
-      <pre><span class="{$ctype}">
-
-      <xsl:for-each select="str:tokenize_plasmaroo(., $newline)">
-        <xsl:choose>
-          <xsl:when test=". = $newline">
-            <xsl:if test="position() != 1"><xsl:value-of 
select='$newline'/></xsl:if>
-            <xsl:if test="$numbering = 'lines' and position() != last()-1">
-              <span style="float: left;"><xsl:number format="01"/>:<xsl:text> 
</xsl:text></span>
-            </xsl:if>
-          </xsl:when>
-          <xsl:otherwise>
-            <xsl:choose>
-              <xsl:when test="$lang = 'ebuild'">
-                <xsl:call-template name="lang.highlight.ebuild.tokenate">
-                  <xsl:with-param name="data" select="."/>
-                </xsl:call-template>
-              </xsl:when>
-              <xsl:when test="$lang = 'make'">
-                <xsl:call-template name="lang.highlight.make.tokenate">
-                  <xsl:with-param name="data" select="."/>
-                </xsl:call-template>
-              </xsl:when>
-              <xsl:when test="$lang = 'm4'">
-                <xsl:call-template name="lang.highlight.m4.tokenate">
-                  <xsl:with-param name="data" select="."/>
-                </xsl:call-template>
-              </xsl:when>
-              <xsl:when test="$lang = 'sgml'">
-                <xsl:call-template name="lang.highlight.sgml.tokenate">
-                  <xsl:with-param name="data" select="."/>
-                </xsl:call-template>
-              </xsl:when>
-              <xsl:when test="$lang = 'c'">
-                <xsl:call-template name="lang.highlight.c.tokenate">
-                  <xsl:with-param name="data" select="."/>
-                </xsl:call-template>
-              </xsl:when>
-              <xsl:otherwise>
-                <xsl:message>Error: Unknown language type (<xsl:value-of 
select="$lang"/>)</xsl:message>
-                <xsl:value-of select="."/>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:otherwise>
-        </xsl:choose>
-      </xsl:for-each>
-      </span></pre>
-  </xsl:template>
-
-  <xsl:template match="figure">
-    <div class="figure">
-      <div class="image"><img alt="{@short}" src="{@link}"/></div>
-      <xsl:if test="@caption">
-        <p class="caption"><xsl:value-of select="@caption"/></p>
-      </xsl:if>
-    </div>
-  </xsl:template>
-
-  <!-- Lists -->
-  <xsl:template match="li">
-    <li><xsl:apply-templates/></li>
-  </xsl:template>
-
-  <xsl:template match="ol">
-    <ol><xsl:apply-templates/></ol>
-  </xsl:template>
+</xsl:template>
 
-  <xsl:template match="ul">
-    <xsl:choose>
-      <xsl:when test="@class='list-group'">
-        <ul class="list-group fix-links">
-          <xsl:for-each select="li">
-            <li class="list-group-item">
-              <xsl:apply-templates>
-                <xsl:with-param name="class">list-group-item</xsl:with-param>
-              </xsl:apply-templates>
-            </li>
-          </xsl:for-each>
-        </ul>
-      </xsl:when>
-      <xsl:otherwise>
-        <ul><xsl:apply-templates/></ul>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
+<!-- Table Item -->
+<xsl:template match="ti">
+  <td>
+    <xsl:if test="@colspan">
+      <xsl:attribute name="colspan"><xsl:value-of 
select="@colspan"/></xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@rowspan">
+      <xsl:attribute name="rowspan"><xsl:value-of 
select="@rowspan"/></xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@nowrap">
+      <!-- Disable word wrapping for this table item. Usage: <ti 
nowrap="nowrap"> -->
+      <xsl:attribute name="nowrap"><xsl:value-of 
select="@nowrap"/></xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates/>
+  </td>
+</xsl:template>
+
+<!-- Table Heading -->
+<xsl:template match="th">
+  <th>
+    <xsl:if test="@colspan">
+      <xsl:attribute name="colspan"><xsl:value-of 
select="@colspan"/></xsl:attribute>
+      <!-- Center only when item spans several columns as
+           centering all <th> might disrupt some pages.
+           We might want to use a plain html <th> tag later.
+           Tip: to center a single-cell title, use <th colspan="1">
+      -->
+      <xsl:attribute name="style">text-align:center</xsl:attribute>
+    </xsl:if>
+    <xsl:if test="@rowspan">
+      <xsl:attribute name="rowspan"><xsl:value-of 
select="@rowspan"/></xsl:attribute>
+    </xsl:if>
+    <xsl:apply-templates/>
+  </th>
+</xsl:template>
+<!-- End Table Jojo -->
+
+<!-- FIXME: Handle lang=... -->
+<xsl:template match="codesample">
+  <xsl:variable name="ctype"><xsl:if test="@lang = 
'ebuild'">Constant</xsl:if></xsl:variable>
+  <xsl:variable name="numbering" select="@numbering"/>
+  <xsl:variable name="lang" select="@lang"/>
+  <pre><span class="{$ctype}">
+
+    <xsl:for-each select="str:tokenize_plasmaroo(., $newline)">
+      <xsl:choose>
+        <xsl:when test=". = $newline">
+          <xsl:if test="position() != 1"><xsl:value-of 
select='$newline'/></xsl:if>
+          <xsl:if test="$numbering = 'lines' and position() != last()-1">
+            <span style="float: left;"><xsl:number format="01"/>:<xsl:text> 
</xsl:text></span>
+          </xsl:if>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:choose>
+            <xsl:when test="$lang = 'ebuild'">
+              <xsl:call-template name="lang.highlight.ebuild.tokenate">
+                <xsl:with-param name="data" select="."/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$lang = 'make'">
+              <xsl:call-template name="lang.highlight.make.tokenate">
+                <xsl:with-param name="data" select="."/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$lang = 'm4'">
+              <xsl:call-template name="lang.highlight.m4.tokenate">
+                <xsl:with-param name="data" select="."/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$lang = 'sgml'">
+              <xsl:call-template name="lang.highlight.sgml.tokenate">
+                <xsl:with-param name="data" select="."/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:when test="$lang = 'c'">
+              <xsl:call-template name="lang.highlight.c.tokenate">
+                <xsl:with-param name="data" select="."/>
+              </xsl:call-template>
+            </xsl:when>
+            <xsl:otherwise>
+              <xsl:message>Error: Unknown language type (<xsl:value-of 
select="$lang"/>)</xsl:message>
+              <xsl:value-of select="."/>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:for-each>
+  </span></pre>
+</xsl:template>
+
+<xsl:template match="figure">
+  <div class="figure">
+    <div class="image"><img alt="{@short}" src="{@link}"/></div>
+    <xsl:if test="@caption">
+      <p class="caption"><xsl:value-of select="@caption"/></p>
+    </xsl:if>
+  </div>
+</xsl:template>
+
+<!-- Lists -->
+<xsl:template match="li">
+  <li><xsl:apply-templates/></li>
+</xsl:template>
+
+<xsl:template match="ol">
+  <ol><xsl:apply-templates/></ol>
+</xsl:template>
+
+<xsl:template match="ul">
+  <xsl:choose>
+    <xsl:when test="@class='list-group'">
+      <ul class="list-group fix-links">
+        <xsl:for-each select="li">
+          <li class="list-group-item">
+            <xsl:apply-templates>
+              <xsl:with-param name="class">list-group-item</xsl:with-param>
+            </xsl:apply-templates>
+          </li>
+        </xsl:for-each>
+      </ul>
+    </xsl:when>
+    <xsl:otherwise>
+      <ul><xsl:apply-templates/></ul>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
 
-  <!-- Definition Lists -->
-  <xsl:template match="dl">
-    <dl><xsl:apply-templates/></dl>
-  </xsl:template>
+<!-- Definition Lists -->
+<xsl:template match="dl">
+  <dl><xsl:apply-templates/></dl>
+</xsl:template>
 
-  <xsl:template match="dt">
-    <dt><xsl:apply-templates/></dt>
-  </xsl:template>
+<xsl:template match="dt">
+  <dt><xsl:apply-templates/></dt>
+</xsl:template>
 
-  <xsl:template match="dd">
-    <dd><xsl:apply-templates/></dd>
-  </xsl:template>
+<xsl:template match="dd">
+  <dd><xsl:apply-templates/></dd>
+</xsl:template>
 
-  <xsl:template match="note">
-    <div class="alert alert-info" role="alert">
+<xsl:template match="note">
+  <div class="alert alert-info" role="alert">
     <strong>Note:</strong>
     <xsl:apply-templates/>
-    </div>
-  </xsl:template>
+  </div>
+</xsl:template>
 
-  <xsl:template match="important">
-    <div class="alert alert-warning" role="alert">
+<xsl:template match="important">
+  <div class="alert alert-warning" role="alert">
     <strong>Important:</strong>
     <xsl:apply-templates/>
-    </div>
-  </xsl:template>
+  </div>
+</xsl:template>
 
-  <xsl:template match="warning">
-    <div class="alert alert-danger" role="alert">
+<xsl:template match="warning">
+  <div class="alert alert-danger" role="alert">
     <strong>Warning:</strong>
     <xsl:apply-templates/>
-    </div>
-  </xsl:template>
+  </div>
+</xsl:template>
 
-  <xsl:template match="todo">
-    <div class="alert alert-info" role="alert">
+<xsl:template match="todo">
+  <div class="alert alert-info" role="alert">
     <strong>Todo:</strong>
     <xsl:apply-templates/>
-    </div>
-  </xsl:template>
-
-  <xsl:template match="b">
-    <b><xsl:apply-templates/></b>
-  </xsl:template>
-
-  <xsl:template match="d">
-    <xsl:text>&#8212;</xsl:text>
-  </xsl:template>
-
-  <xsl:template match="e">
-    <i><xsl:apply-templates/></i>
-  </xsl:template>
-
-  <xsl:template match="c">
-    <code class="docutils literal"><span 
class="pre"><xsl:apply-templates/></span></code>
-  </xsl:template>
-
-  <xsl:template name="convert-to-anchor">
-    <xsl:param name="data"/>
-    <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz-</xsl:variable>
-    <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ<xsl:text> 
</xsl:text></xsl:variable>
-    <xsl:variable name="lcdata" select="translate(normalize-space($data), 
$ucletters, $lcletters)"/>
-    <!-- Delete anything but letters, digits, hyphen, dot, underscore -->
-    <xsl:variable 
name="allowed">abcdefghijklmnopqrstuvwxyz0123456789-._</xsl:variable>
-    <xsl:value-of select="translate($lcdata, translate($lcdata, $allowed, ''), 
'')"/>
-  </xsl:template>
-
-  <xsl:template match="uri">
-    <xsl:param name="class" />
-    <xsl:choose>
-      <xsl:when test="starts-with(@link, '::')">
-      <!-- Ideally we would work out how many levels to nest down to save a 
few bytes but
-           going down to root level works just as well (and is faster). -->
-        <xsl:variable name="relative_path_depth" 
select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , 
''))"/>
-        <xsl:variable name="relative_path_depth_recursion">
-          <xsl:call-template name="str:repeatString">
-            <xsl:with-param name="count" select="$relative_path_depth"/>
-            <xsl:with-param name="append">../</xsl:with-param>
-          </xsl:call-template>
-        </xsl:variable>
-        <xsl:choose>
-          <xsl:when test="contains(@link, '##')">
-            <xsl:variable name="slash">
-              <xsl:if test="substring(substring-before(@link, '##'), 
string-length(substring-before(@link, '##'))) != '/'">/</xsl:if>
-            </xsl:variable>
-            <a class="{$class}" href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '##'), '::'), $slash, 'index.html#', 
substring-after(@link, '##'))}"><xsl:value-of select="."/></a>
-          </xsl:when>
-          <xsl:when test="contains(@link, '#')">
-            <xsl:variable name="anchor">
-              <xsl:call-template name="convert-to-anchor">
-                <xsl:with-param name="data" select="substring-after(@link, 
'#')"/>
-              </xsl:call-template>
-            </xsl:variable>
-            <xsl:variable name="slash">
-              <xsl:if test="substring(substring-before(@link, '#'), 
string-length(substring-before(@link, '#'))) != '/'">/</xsl:if>
-            </xsl:variable>
-            <xsl:choose>
-              <xsl:when test=". != ''">
-                <a class="{$class}" 
href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '#'), '::'), $slash, 'index.html#', 
$anchor)}"><xsl:value-of select="."/></a>
-              </xsl:when>
-              <xsl:otherwise>
-                <a class="{$class}" 
href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '#'), '::'), $slash, 'index.html#', 
$anchor)}"><xsl:value-of select="substring-after(@link, '#')"/></a>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:when>
-          <xsl:otherwise>
-            <xsl:variable name="slash">
-              <xsl:if test="substring(@link, string-length(@link)) != 
'/'">/</xsl:if>
-            </xsl:variable>
-            <xsl:choose>
-              <xsl:when test=". != ''">
-                <a class="{$class}" 
href="{concat($relative_path_depth_recursion, substring-after(@link, '::'), 
$slash, 'index.html')}"><xsl:value-of select="."/></a>
-              </xsl:when>
-              <xsl:when test="starts-with(@link, '::eclass-reference/') and 
substring-after(@link, '::eclass-reference/') != ''">
-                <!-- Eclass reference pages are generated with man2html,
-                     so there isn't any text.xml that could be loaded.
-                     Use the name of the eclass as link text. #442194 -->
-                <a class="{$class}" 
href="{concat($relative_path_depth_recursion, substring-after(@link, '::'), 
$slash, 'index.html')}"><xsl:value-of 
select="substring-before(concat(substring-after(@link, '::eclass-reference/'), 
$slash), '/')"/></a>
-              </xsl:when>
-              <xsl:otherwise>
-                <a class="{$class}" 
href="{concat($relative_path_depth_recursion, substring-after(@link, '::'), 
$slash, 'index.html')}"><xsl:value-of select="document(concat(/guide/@self, 
$relative_path_depth_recursion, substring-after(@link, '::'), 
'/text.xml'))/guide/chapter[1]/title"/></a>
-              </xsl:otherwise>
-            </xsl:choose>
-          </xsl:otherwise>
-        </xsl:choose>
-      </xsl:when>
-      <xsl:when test="@link">
-        <a class="{$class}" href="{@link}"><xsl:value-of select="."/></a>
-      </xsl:when>
-      <xsl:when test="contains(., '://')">
-        <a class="{$class}" href="{.}"><xsl:value-of select="."/></a>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:message>Error: No link target (<xsl:value-of 
select="."/>)</xsl:message>
-        <a class="{$class}"><xsl:value-of select="."/></a>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <!-- TOC Tree -->
-  <xsl:template match="contentsTree" name="contentsTree">
-    <xsl:param name="depth" select="0"/>
-    <xsl:param name="maxdepth">
-      <xsl:choose>
-        <xsl:when test="@maxdepth"><xsl:value-of 
select="@maxdepth"/></xsl:when>
-        <xsl:otherwise>0</xsl:otherwise>
-      </xsl:choose>
-    </xsl:param>
-    <xsl:param name="path">
-      <xsl:choose>
-        <xsl:when test="@root"><xsl:value-of select="@root"/></xsl:when>
-        <xsl:otherwise><xsl:value-of select="/guide/@self"/></xsl:otherwise>
-      </xsl:choose>
-    </xsl:param>
-    <xsl:param name="path_rel">
-      <xsl:if test="$depth = 0 and $path = '' and /guide/@self != ''">
+  </div>
+</xsl:template>
+
+<xsl:template match="b">
+  <b><xsl:apply-templates/></b>
+</xsl:template>
+
+<xsl:template match="d">
+  <xsl:text>&#8212;</xsl:text>
+</xsl:template>
+
+<xsl:template match="e">
+  <i><xsl:apply-templates/></i>
+</xsl:template>
+
+<xsl:template match="c">
+  <code class="docutils literal"><span 
class="pre"><xsl:apply-templates/></span></code>
+</xsl:template>
+
+<xsl:template name="convert-to-anchor">
+  <xsl:param name="data"/>
+  <xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz-</xsl:variable>
+  <xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ<xsl:text> 
</xsl:text></xsl:variable>
+  <xsl:variable name="lcdata" select="translate(normalize-space($data), 
$ucletters, $lcletters)"/>
+  <!-- Delete anything but letters, digits, hyphen, dot, underscore -->
+  <xsl:variable 
name="allowed">abcdefghijklmnopqrstuvwxyz0123456789-._</xsl:variable>
+  <xsl:value-of select="translate($lcdata, translate($lcdata, $allowed, ''), 
'')"/>
+</xsl:template>
+
+<xsl:template match="uri">
+  <xsl:param name="class" />
+  <xsl:choose>
+    <xsl:when test="starts-with(@link, '::')">
+      <!-- Ideally we would work out how many levels to nest down to save
+           a few bytes but going down to root level works just as well
+           (and is faster). -->
+      <xsl:variable name="relative_path_depth"
+                    select="string-length(/guide/@self) - 
string-length(translate(/guide/@self, '/' , ''))"/>
+      <xsl:variable name="relative_path_depth_recursion">
         <xsl:call-template name="str:repeatString">
-          <xsl:with-param name="count" 
select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , 
''))"/>
+          <xsl:with-param name="count" select="$relative_path_depth"/>
           <xsl:with-param name="append">../</xsl:with-param>
         </xsl:call-template>
-      </xsl:if>
-    </xsl:param>
-    <xsl:param name="extraction" select="@extraction"/>
-    <xsl:param name="extraction_counting"/>
+      </xsl:variable>
+      <xsl:choose>
+        <xsl:when test="contains(@link, '##')">
+          <xsl:variable name="slash">
+            <xsl:if test="substring(substring-before(@link, '##'),
+                          string-length(substring-before(@link, '##'))) != 
'/'">/</xsl:if>
+          </xsl:variable>
+          <a class="{$class}"
+             href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '##'), '::'),
+                   $slash, 'index.html#', substring-after(@link, '##'))}">
+            <xsl:value-of select="."/>
+          </a>
+        </xsl:when>
+        <xsl:when test="contains(@link, '#')">
+          <xsl:variable name="anchor">
+            <xsl:call-template name="convert-to-anchor">
+              <xsl:with-param name="data" select="substring-after(@link, 
'#')"/>
+            </xsl:call-template>
+          </xsl:variable>
+          <xsl:variable name="slash">
+            <xsl:if test="substring(substring-before(@link, '#'),
+                          string-length(substring-before(@link, '#'))) != 
'/'">/</xsl:if>
+          </xsl:variable>
+          <xsl:choose>
+            <xsl:when test=". != ''">
+              <a class="{$class}"
+                 href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '#'), '::'),
+                       $slash, 'index.html#', $anchor)}">
+                <xsl:value-of select="."/>
+              </a>
+            </xsl:when>
+            <xsl:otherwise>
+              <a class="{$class}"
+                 href="{concat($relative_path_depth_recursion, 
substring-after(substring-before(@link, '#'), '::'),
+                       $slash, 'index.html#', $anchor)}">
+                <xsl:value-of select="substring-after(@link, '#')"/>
+              </a>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:when>
+        <xsl:otherwise>
+          <xsl:variable name="slash">
+            <xsl:if test="substring(@link, string-length(@link)) != 
'/'">/</xsl:if>
+          </xsl:variable>
+          <xsl:choose>
+            <xsl:when test=". != ''">
+              <a class="{$class}"
+                 href="{concat($relative_path_depth_recursion, 
substring-after(@link, '::'), $slash, 'index.html')}">
+                <xsl:value-of select="."/>
+              </a>
+            </xsl:when>
+            <xsl:when test="starts-with(@link, '::eclass-reference/')
+                            and substring-after(@link, '::eclass-reference/') 
!= ''">
+              <!-- Eclass reference pages are generated with man2html,
+                   so there isn't any text.xml that could be loaded.
+                   Use the name of the eclass as link text. #442194 -->
+              <a class="{$class}"
+                 href="{concat($relative_path_depth_recursion, 
substring-after(@link, '::'), $slash, 'index.html')}">
+                <xsl:value-of 
select="substring-before(concat(substring-after(@link, '::eclass-reference/'), 
$slash), '/')"/>
+              </a>
+            </xsl:when>
+            <xsl:otherwise>
+              <a class="{$class}"
+                 href="{concat($relative_path_depth_recursion, 
substring-after(@link, '::'), $slash, 'index.html')}">
+                <xsl:value-of select="document(concat(/guide/@self, 
$relative_path_depth_recursion,
+                                      substring-after(@link, '::'), 
'/text.xml'))/guide/chapter[1]/title"/>
+              </a>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:when>
+    <xsl:when test="@link">
+      <a class="{$class}" href="{@link}"><xsl:value-of select="."/></a>
+    </xsl:when>
+    <xsl:when test="contains(., '://')">
+      <a class="{$class}" href="{.}"><xsl:value-of select="."/></a>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:message>Error: No link target (<xsl:value-of 
select="."/>)</xsl:message>
+      <a class="{$class}"><xsl:value-of select="."/></a>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
 
-    <xsl:variable name="doc_self" select="concat($path, 'text.xml')"/>
-    <xsl:if test="count(document($doc_self)/guide/include) &gt; 0 and ($depth 
&lt; $maxdepth or $maxdepth = '0')">
+<!-- TOC Tree -->
+<xsl:template match="contentsTree" name="contentsTree">
+  <xsl:param name="depth" select="0"/>
+  <xsl:param name="maxdepth">
+    <xsl:choose>
+      <xsl:when test="@maxdepth"><xsl:value-of select="@maxdepth"/></xsl:when>
+      <xsl:otherwise>0</xsl:otherwise>
+    </xsl:choose>
+  </xsl:param>
+  <xsl:param name="path">
+    <xsl:choose>
+      <xsl:when test="@root"><xsl:value-of select="@root"/></xsl:when>
+      <xsl:otherwise><xsl:value-of select="/guide/@self"/></xsl:otherwise>
+    </xsl:choose>
+  </xsl:param>
+  <xsl:param name="path_rel">
+    <xsl:if test="$depth = 0 and $path = '' and /guide/@self != ''">
+      <xsl:call-template name="str:repeatString">
+        <xsl:with-param name="count"
+                        select="string-length(/guide/@self) - 
string-length(translate(/guide/@self, '/' , ''))"/>
+        <xsl:with-param name="append">../</xsl:with-param>
+      </xsl:call-template>
+    </xsl:if>
+  </xsl:param>
+  <xsl:param name="extraction" select="@extraction"/>
+  <xsl:param name="extraction_counting"/>
+
+  <xsl:variable name="doc_self" select="concat($path, 'text.xml')"/>
+  <xsl:if test="count(document($doc_self)/guide/include) &gt; 0 and ($depth 
&lt; $maxdepth or $maxdepth = '0')">
     <xsl:choose>
       <xsl:when test="$extraction_counting = 1">
         <xsl:for-each select="document($doc_self)/guide/include">
-          <count value="{count(document(concat($path, @href, 
'text.xml'))//*[name()=$extraction])}" path="{concat($path, @href)}">
+          <count value="{count(document(concat($path, @href, 
'text.xml'))//*[name()=$extraction])}"
+                 path="{concat($path, @href)}">
             <xsl:call-template name="contentsTree">
               <xsl:with-param name="depth" select="$depth + 1"/>
               <xsl:with-param name="maxdepth" select="$maxdepth"/>
@@ -395,45 +424,50 @@
                 <xsl:with-param name="extraction_counting" select="1"/>
               </xsl:call-template>
             </xsl:variable>
-            <xsl:variable name="extraction_counter" 
select="count(exslt:node-set($extraction_counter_node)//*[@value != 0]) + 
count(document(concat($path, @href, 'text.xml'))//*[name()=$extraction])"/>
+            <xsl:variable name="extraction_counter"
+                          
select="count(exslt:node-set($extraction_counter_node)//*[@value != 0])
+                                  + count(document(concat($path, @href, 
'text.xml'))//*[name()=$extraction])"/>
             <xsl:if test="string($extraction) = '' or $extraction_counter &gt; 
0">
-            <li>
-              <a class="reference" href="{concat($path_rel, @href, 
'index.html')}"><xsl:value-of select="document(concat($path, @href, 
'text.xml'))/guide/chapter[1]/title"/></a>
-              <xsl:if test="$extraction != ''">
-                <ul>
-                <xsl:for-each select="document(concat($path, @href, 
'text.xml'))//*[name()=$extraction]">
-                  <xsl:variable name="extraction_id" select="position()"/>
-                  <li><xsl:apply-templates 
select="(//*[name()=$extraction])[position()=$extraction_id]"/></li>
-                </xsl:for-each>
-                </ul>
-              </xsl:if>
-              <xsl:call-template name="contentsTree">
-                <xsl:with-param name="depth" select="$depth + 1"/>
-                <xsl:with-param name="maxdepth" select="$maxdepth"/>
-                <xsl:with-param name="path" select="concat($path, @href)"/>
-                <xsl:with-param name="path_rel" select="concat($path_rel, 
@href)"/>
-                <xsl:with-param name="extraction" select="$extraction"/>
-              </xsl:call-template>
-            </li>
+              <li>
+                <a class="reference" href="{concat($path_rel, @href, 
'index.html')}">
+                  <xsl:value-of select="document(concat($path, @href, 
'text.xml'))/guide/chapter[1]/title"/>
+                </a>
+                <xsl:if test="$extraction != ''">
+                  <ul>
+                    <xsl:for-each select="document(concat($path, @href, 
'text.xml'))//*[name()=$extraction]">
+                      <xsl:variable name="extraction_id" select="position()"/>
+                      <li><xsl:apply-templates 
select="(//*[name()=$extraction])[position()=$extraction_id]"/></li>
+                    </xsl:for-each>
+                  </ul>
+                </xsl:if>
+                <xsl:call-template name="contentsTree">
+                  <xsl:with-param name="depth" select="$depth + 1"/>
+                  <xsl:with-param name="maxdepth" select="$maxdepth"/>
+                  <xsl:with-param name="path" select="concat($path, @href)"/>
+                  <xsl:with-param name="path_rel" select="concat($path_rel, 
@href)"/>
+                  <xsl:with-param name="extraction" select="$extraction"/>
+                </xsl:call-template>
+              </li>
             </xsl:if>
           </xsl:for-each>
         </ul>
       </xsl:otherwise>
     </xsl:choose>
-    </xsl:if>
-  </xsl:template>
-
-  <xsl:template match="/">
-    <xsl:variable name="relative_path_depth" 
select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , 
''))"/>
-    <xsl:variable name="relative_path_depth_recursion">
-      <xsl:call-template name="str:repeatString">
-        <xsl:with-param name="count" select="$relative_path_depth"/>
-        <xsl:with-param name="append">../</xsl:with-param>
-      </xsl:call-template>
-    </xsl:variable>
-    <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
-    <xsl:value-of select='$newline'/>
-    <html lang="en">
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="/">
+  <xsl:variable name="relative_path_depth"
+                select="string-length(/guide/@self) - 
string-length(translate(/guide/@self, '/' , ''))"/>
+  <xsl:variable name="relative_path_depth_recursion">
+    <xsl:call-template name="str:repeatString">
+      <xsl:with-param name="count" select="$relative_path_depth"/>
+      <xsl:with-param name="append">../</xsl:with-param>
+    </xsl:call-template>
+  </xsl:variable>
+  <xsl:text disable-output-escaping='yes'>&lt;!DOCTYPE html&gt;</xsl:text>
+  <xsl:value-of select='$newline'/>
+  <html lang="en">
     <head>
       <title><xsl:value-of select="/guide/chapter[1]/title"/> &#x2013; Gentoo 
Development Guide</title>
       <meta name="viewport" content="width=device-width, initial-scale=1.0" />
@@ -503,7 +537,8 @@
               <div class="container">
                 <div class="row">
                   <div class="navbar-header">
-                    <button type="button" class="navbar-toggle" 
data-toggle="collapse" data-target=".navbar-main-collapse">
+                    <button type="button" class="navbar-toggle"
+                            data-toggle="collapse" 
data-target=".navbar-main-collapse">
                       <span class="sr-only">Toggle navigation</span>
                       <span class="icon-bar"></span>
                       <span class="icon-bar"></span>
@@ -512,7 +547,9 @@
                   </div>
                   <div class="collapse navbar-collapse navbar-main-collapse">
                     <ul class="nav navbar-nav">
-                      <li><a 
href="{$relative_path_depth_recursion}index.html"><span class="fa 
fa-home"/>&#160;Home</a></li>
+                      <li>
+                        <a 
href="{$relative_path_depth_recursion}index.html"><span class="fa 
fa-home"/>&#160;Home</a>
+                      </li>
                       <li class="dropdown">
                         <a href="#" class="dropdown-toggle" 
data-toggle="dropdown">Index&#160;<span class="caret"></span></a>
                         <xsl:if test="/guide/chapter[1]/section or 
//contentsTree">
@@ -553,9 +590,11 @@
               <div class="container">
                 <div class="row">
                   <div class="input-group">
-                    <input type="search" name="search" placeholder="Search" 
title="Search Gentoo Developer Manual [f]" accesskey="f" id="searchInput" 
class="form-control" onclick="fetchDocuments()"/>
+                    <input type="search" name="search" placeholder="Search" 
title="Search Gentoo Developer Manual [f]"
+                           accesskey="f" id="searchInput" class="form-control" 
onclick="fetchDocuments()"/>
                     <div class="input-group-btn">
-                      <input type="submit" name="fulltext" value="Search" 
title="Search the pages for this text" id="mw-searchButton" class="searchButton 
btn btn-default" onclick="search()"/>
+                      <input type="submit" name="fulltext" value="Search" 
title="Search the pages for this text"
+                             id="mw-searchButton" class="searchButton btn 
btn-default" onclick="search()"/>
                     </div>
                   </div>
                 </div>
@@ -635,14 +674,14 @@
         <script src="{$relative_path_depth_recursion}search.js"></script>
       </xsl:if>
     </body>
-    </html>
-  </xsl:template>
-
-  <xsl:template name="str:repeatString">
-    <xsl:param name="string"/>
-    <xsl:param name="count"/>
-    <xsl:param name="append"/>
-    <xsl:choose>
+  </html>
+</xsl:template>
+
+<xsl:template name="str:repeatString">
+  <xsl:param name="string"/>
+  <xsl:param name="count"/>
+  <xsl:param name="append"/>
+  <xsl:choose>
     <xsl:when test="$count != 0">
       <xsl:call-template name="str:repeatString">
         <xsl:with-param name="string" select="concat($string, $append)"/>
@@ -653,192 +692,205 @@
     <xsl:otherwise>
       <xsl:value-of select="$string"/>
     </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <xsl:template name="findNext">
-    <xsl:param name="self" select="/guide/@self"/>
-    <xsl:choose>
-      <!-- To find the "next" node:
-           * See if this node includes any subnodes... if it does, that is
-             our next node
-           * Look at our parent and see if it includes any nodes after us, if
-             it does use it.
-           * Repeat recursively, going down parents if needed.
-           * End at the root item if needed.
-      -->
-      <xsl:when test="count(/guide/include) &gt; 0">
-        <xsl:variable name="doc" select="/guide/include[1]/@href"/>
-        <a class="w-250 text-center" href="{concat($doc, 'index.html')}">
-          <span class="truncated-text d-inline-block max-w-200 mr-2">
-            <xsl:value-of select="document(concat(/guide/@self, $doc, 
'text.xml'))/guide/chapter[1]/title"/>
-          </span>
-          <span class="fa fa-arrow-right"/>
-        </a>
-      </xsl:when>
-      <xsl:otherwise>
-        <!-- This document's path -->
-        <xsl:variable name="doc_self" select="concat($self, 'text.xml')"/>
-        <!-- Turn the absolute path into a relative path so we can find 
ourselves in
-             the parent -->
-        <xsl:variable name="path_self" select="concat(str:tokenize($self, 
'/')[last()], '/')"/>
-        <xsl:variable name="index_self" select="count(document(concat($self, 
'../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)+1"/>
-        <!-- Go down a parent, lookup the item after us... -->
-        <xsl:variable name="parentItem_lookup" select="document(concat($self, 
'../text.xml'))/guide/include[$index_self]/@href"/>
-        <xsl:variable name="parentItem_next" 
select="concat(document(concat($self, '../text.xml'))/guide/@self, 
$parentItem_lookup)"/>
-        <xsl:choose>
-          <!-- If we have an item after us, or we are at the root node 
(termination condition) we need to
-               not recurse any further... -->
-          <xsl:when test="$parentItem_lookup != '' or document(concat($self, 
'../text.xml'))/guide/@root">
-            <xsl:variable name="parentItem_actual">
-              <xsl:choose>
-                <xsl:when test="$parentItem_next = ''"></xsl:when>
-                <xsl:otherwise><xsl:value-of 
select="$parentItem_next"/></xsl:otherwise>
-              </xsl:choose>
-            </xsl:variable>
-            <!-- This is where we do a little trickery. To count how many 
levels we need to go down,
-                 we count how far up we currently are (remember that the 
absolute link we get is relative to /...) and
-                 hence we can build a relative link... -->
-            <xsl:variable name="relative_path" select="$parentItem_actual"/>
-            <xsl:variable name="relative_path_depth" 
select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/' , 
''))"/>
-            <xsl:variable name="relative_path_depth_recursion">
-              <xsl:call-template name="str:repeatString">
-                <xsl:with-param name="count" select="$relative_path_depth"/>
-                <xsl:with-param name="append">../</xsl:with-param>
-              </xsl:call-template>
-            </xsl:variable>
-            <a class="w-250 text-center" 
href="{concat($relative_path_depth_recursion, $relative_path, 'index.html')}">
-              <span class="truncated-text d-inline-block max-w-200 mr-2">
-                <xsl:value-of select="document(concat($parentItem_actual, 
'text.xml'))/guide/chapter[1]/title"/>
-              </span>
-              <span class="fa fa-arrow-right"/>
-            </a>
-          </xsl:when>
-          <xsl:otherwise>
-            <!-- We need to recurse downwards; so we need to strip off a 
directory element off our absolute path to feed
-                 into the next iteration... -->
-            <xsl:variable name="relative_path_depth" 
select="string-length($self)-string-length(translate($self, '/' , ''))"/>
-            <xsl:variable name="relative_path_fixed">
-              <xsl:for-each select="str:tokenize_plasmaroo($self, 
'/')[position() &lt; (($relative_path_depth - 1)*2 + 1)]">
-                <xsl:value-of select="."/>
-              </xsl:for-each>
-            </xsl:variable>
-            <xsl:call-template name="findNext">
-              <xsl:with-param name="self" select="$relative_path_fixed"/>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="findNext">
+  <xsl:param name="self" select="/guide/@self"/>
+  <xsl:choose>
+    <!-- To find the "next" node:
+         * See if this node includes any subnodes... if it does, that is
+           our next node
+         * Look at our parent and see if it includes any nodes after us,
+           if it does use it.
+         * Repeat recursively, going down parents if needed.
+         * End at the root item if needed.
+    -->
+    <xsl:when test="count(/guide/include) &gt; 0">
+      <xsl:variable name="doc" select="/guide/include[1]/@href"/>
+      <a class="w-250 text-center" href="{concat($doc, 'index.html')}">
+        <span class="truncated-text d-inline-block max-w-200 mr-2">
+          <xsl:value-of select="document(concat(/guide/@self, $doc, 
'text.xml'))/guide/chapter[1]/title"/>
+        </span>
+        <span class="fa fa-arrow-right"/>
+      </a>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- This document's path -->
+      <xsl:variable name="doc_self" select="concat($self, 'text.xml')"/>
+      <!-- Turn the absolute path into a relative path so we can find ourselves
+           in the parent -->
+      <xsl:variable name="path_self" select="concat(str:tokenize($self, 
'/')[last()], '/')"/>
+      <xsl:variable name="index_self"
+                    select="count(document(concat($self, 
'../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)+1"/>
+      <!-- Go down a parent, lookup the item after us... -->
+      <xsl:variable name="parentItem_lookup"
+                    select="document(concat($self, 
'../text.xml'))/guide/include[$index_self]/@href"/>
+      <xsl:variable name="parentItem_next"
+                    select="concat(document(concat($self, 
'../text.xml'))/guide/@self, $parentItem_lookup)"/>
+      <xsl:choose>
+        <!-- If we have an item after us, or we are at the root node
+             (termination condition) we need to not recurse any further... -->
+        <xsl:when test="$parentItem_lookup != '' or document(concat($self, 
'../text.xml'))/guide/@root">
+          <xsl:variable name="parentItem_actual">
+            <xsl:choose>
+              <xsl:when test="$parentItem_next = ''"></xsl:when>
+              <xsl:otherwise><xsl:value-of 
select="$parentItem_next"/></xsl:otherwise>
+            </xsl:choose>
+          </xsl:variable>
+          <!-- This is where we do a little trickery. To count how many levels
+               we need to go down, we count how far up we currently are
+               (remember that the absolute link we get is relative to /...)
+               and hence we can build a relative link... -->
+          <xsl:variable name="relative_path" select="$parentItem_actual"/>
+          <xsl:variable name="relative_path_depth"
+                        select="string-length(/guide/@self) - 
string-length(translate(/guide/@self, '/' , ''))"/>
+          <xsl:variable name="relative_path_depth_recursion">
+            <xsl:call-template name="str:repeatString">
+              <xsl:with-param name="count" select="$relative_path_depth"/>
+              <xsl:with-param name="append">../</xsl:with-param>
             </xsl:call-template>
-          </xsl:otherwise>
-        </xsl:choose>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <xsl:template name="getLastNode">
-    <!-- This function recurses forward down nodes stopping at the very last 
include... -->
-    <xsl:param name="root"/>
-    <xsl:param name="path"/>
-    <xsl:variable name="include" select="document(concat($root, 
$path))/guide/include[last()]/@href"/>
-    <xsl:choose>
-      <xsl:when test="$include">
-        <xsl:call-template name="getLastNode">
-          <xsl:with-param name="root" select="$root"/>
-          <xsl:with-param name="path" select="concat(substring-before($path, 
'text.xml'), $include, 'text.xml')"/>
-        </xsl:call-template>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:value-of select="$path"/>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <xsl:template name="findPrevious">
-    <xsl:choose>
-      <!-- To find the "previous" node:
-           * Go down to our parent
-             * See if there are any nodes before us
-               * If we have a valid node that is before us
-               * Fully recurse up the node to get the last extremity
-             * Otherwise list the parent -->
-      <xsl:when test="/guide/@root">
-        <a class="w-250 text-center" href="#">
-          <span class="fa fa-arrow-left"/>
-          <span class="truncated-text d-inline-block max-w-200 ml-2">
-            <xsl:value-of select="/guide/chapter[1]/title"/>
-          </span>
-        </a>
-      </xsl:when>
-      <xsl:otherwise>
-        <!-- This document's path -->
-        <xsl:variable name="doc_self" select="concat(/guide/@self, 
'text.xml')"/>
-        <!-- Turn the absolute path we have into a relative path so we can 
find ourselves in the
-             parent -->
-        <!-- FIXME: Bombproof the doc_self so it still works if it's missing a 
'/' on the end -->
-        <xsl:variable name="path_self" 
select="concat(str:tokenize(/guide/@self, '/')[last()], '/')"/>
-        <xsl:variable name="index_self" 
select="count(document(concat(/guide/@self, 
'../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)-1"/>
-        <xsl:choose>
-          <xsl:when test="$index_self &gt; 0">
-            <!-- Relative path of the parent -->
-            <xsl:variable name="parentItem_path" 
select="document(concat(/guide/@self, '../text.xml'))/guide/@self"/>
-            <!-- Previous item in the parent -->
-            <xsl:variable name="parentItem_next" 
select="document(concat(/guide/@self, 
'../text.xml'))/guide/include[$index_self]/@href"/>
-            <xsl:variable name="myItem_path">
+          </xsl:variable>
+          <a class="w-250 text-center" 
href="{concat($relative_path_depth_recursion, $relative_path, 'index.html')}">
+            <span class="truncated-text d-inline-block max-w-200 mr-2">
+              <xsl:value-of select="document(concat($parentItem_actual, 
'text.xml'))/guide/chapter[1]/title"/>
+            </span>
+            <span class="fa fa-arrow-right"/>
+          </a>
+        </xsl:when>
+        <xsl:otherwise>
+          <!-- We need to recurse downwards; so we need to strip off a 
directory
+               element off our absolute path to feed into the next 
iteration... -->
+          <xsl:variable name="relative_path_depth"
+                        select="string-length($self) - 
string-length(translate($self, '/' , ''))"/>
+          <xsl:variable name="relative_path_fixed">
+            <xsl:for-each select="str:tokenize_plasmaroo($self, 
'/')[position() &lt; (($relative_path_depth - 1)*2 + 1)]">
+              <xsl:value-of select="."/>
+            </xsl:for-each>
+          </xsl:variable>
+          <xsl:call-template name="findNext">
+            <xsl:with-param name="self" select="$relative_path_fixed"/>
+          </xsl:call-template>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="getLastNode">
+  <!-- This function recurses forward down nodes stopping at the very last 
include... -->
+  <xsl:param name="root"/>
+  <xsl:param name="path"/>
+  <xsl:variable name="include" select="document(concat($root, 
$path))/guide/include[last()]/@href"/>
+  <xsl:choose>
+    <xsl:when test="$include">
+      <xsl:call-template name="getLastNode">
+        <xsl:with-param name="root" select="$root"/>
+        <xsl:with-param name="path" select="concat(substring-before($path, 
'text.xml'), $include, 'text.xml')"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$path"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="findPrevious">
+  <xsl:choose>
+    <!-- To find the "previous" node:
+         * Go down to our parent
+           * See if there are any nodes before us
+             * If we have a valid node that is before us
+             * Fully recurse up the node to get the last extremity
+           * Otherwise list the parent -->
+    <xsl:when test="/guide/@root">
+      <a class="w-250 text-center" href="#">
+        <span class="fa fa-arrow-left"/>
+        <span class="truncated-text d-inline-block max-w-200 ml-2">
+          <xsl:value-of select="/guide/chapter[1]/title"/>
+        </span>
+      </a>
+    </xsl:when>
+    <xsl:otherwise>
+      <!-- This document's path -->
+      <xsl:variable name="doc_self" select="concat(/guide/@self, 'text.xml')"/>
+      <!-- Turn the absolute path we have into a relative path so we can find
+           ourselves in the parent -->
+      <!-- FIXME: Bombproof the doc_self so it still works if it's missing a 
'/'
+           on the end -->
+      <xsl:variable name="path_self" select="concat(str:tokenize(/guide/@self, 
'/')[last()], '/')"/>
+      <xsl:variable name="index_self" 
select="count(document(concat(/guide/@self, 
'../text.xml'))/guide/include[@href=$path_self]/preceding-sibling::*)-1"/>
+      <xsl:choose>
+        <xsl:when test="$index_self &gt; 0">
+          <!-- Relative path of the parent -->
+          <xsl:variable name="parentItem_path" 
select="document(concat(/guide/@self, '../text.xml'))/guide/@self"/>
+          <!-- Previous item in the parent -->
+          <xsl:variable name="parentItem_next"
+                        select="document(concat(/guide/@self, 
'../text.xml'))/guide/include[$index_self]/@href"/>
+          <xsl:variable name="myItem_path">
             <xsl:call-template name="getLastNode">
               <xsl:with-param name="root" select="$parentItem_path"/>
               <xsl:with-param name="path" select="concat($parentItem_next, 
'text.xml')"/>
             </xsl:call-template>
-            </xsl:variable>
-            <!-- Make a relative <a> link; we need an absolute reference for 
the XSLT processor though... -->
-            <a class="w-250 text-center" href="{concat('../', 
substring-before($myItem_path, 'text.xml'), 'index.html')}">
-              <span class="fa fa-arrow-left"/>
-              <span class="truncated-text d-inline-block max-w-200 ml-2">
-                <xsl:value-of select="document(concat($parentItem_path, 
$myItem_path))/guide/chapter[1]/title"/>
-              </span>
-            </a>
-          </xsl:when>
-          <xsl:otherwise>
-            <a class="w-250 text-center" href="../index.html">
-              <span class="fa fa-arrow-left"/>
-              <span class="truncated-text d-inline-block max-w-200 ml-2">
-                <xsl:value-of select="document(concat(/guide/@self, 
'../text.xml'))/guide/chapter[1]/title"/>
-              </span>
-            </a>
-          </xsl:otherwise>
-        </xsl:choose>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:template>
-
-  <xsl:template name="printParentDocs">
-    <xsl:param name="depth" 
select="string-length(/guide/@self)-string-length(translate(/guide/@self, '/', 
''))"/>
-    <xsl:choose>
-      <xsl:when test="$depth &gt; 0">
-        <xsl:variable name="relative_path_depth_recursion">
-          <xsl:call-template name="str:repeatString">
-            <xsl:with-param name="count" select="$depth"/>
-            <xsl:with-param name="append">../</xsl:with-param>
-          </xsl:call-template>
-        </xsl:variable>
-        <li>
-          <a href="{$relative_path_depth_recursion}index.html">
-            <xsl:value-of select="document(concat(/guide/@self, 
concat($relative_path_depth_recursion, 'text.xml')))/guide/chapter[1]/title"/>
+          </xsl:variable>
+          <!-- Make a relative <a> link; we need an absolute reference
+               for the XSLT processor though... -->
+          <a class="w-250 text-center" href="{concat('../', 
substring-before($myItem_path, 'text.xml'), 'index.html')}">
+            <span class="fa fa-arrow-left"/>
+            <span class="truncated-text d-inline-block max-w-200 ml-2">
+              <xsl:value-of select="document(concat($parentItem_path, 
$myItem_path))/guide/chapter[1]/title"/>
+            </span>
+          </a>
+        </xsl:when>
+        <xsl:otherwise>
+          <a class="w-250 text-center" href="../index.html">
+            <span class="fa fa-arrow-left"/>
+            <span class="truncated-text d-inline-block max-w-200 ml-2">
+              <xsl:value-of select="document(concat(/guide/@self, 
'../text.xml'))/guide/chapter[1]/title"/>
+            </span>
           </a>
-        </li>
-        <xsl:call-template name="printParentDocs">
-          <xsl:with-param name="depth" select="$depth - 1"/>
+        </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="printParentDocs">
+  <xsl:param name="depth" select="string-length(/guide/@self) - 
string-length(translate(/guide/@self, '/', ''))"/>
+  <xsl:choose>
+    <xsl:when test="$depth &gt; 0">
+      <xsl:variable name="relative_path_depth_recursion">
+        <xsl:call-template name="str:repeatString">
+          <xsl:with-param name="count" select="$depth"/>
+          <xsl:with-param name="append">../</xsl:with-param>
         </xsl:call-template>
-      </xsl:when>
-    </xsl:choose>
-  </xsl:template>
-
-  <xsl:template match="author">
-    <dt><xsl:value-of select="@name"/><xsl:if test="@email != ''"> &lt;<a 
href="mailto:{@email}";><xsl:value-of select="@email"/></a>&gt;</xsl:if></dt>
-    <dd><xsl:apply-templates/></dd>
-  </xsl:template>
-
-  <xsl:template match="authors">
-    <dl>
+      </xsl:variable>
+      <li>
+        <a href="{$relative_path_depth_recursion}index.html">
+          <xsl:value-of select="document(concat(/guide/@self, 
concat($relative_path_depth_recursion, 'text.xml')))/guide/chapter[1]/title"/>
+        </a>
+      </li>
+      <xsl:call-template name="printParentDocs">
+        <xsl:with-param name="depth" select="$depth - 1"/>
+      </xsl:call-template>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template match="author">
+  <dt>
+    <xsl:value-of select="@name"/>
+    <xsl:if test="@email != ''"> &lt;<a href="mailto:{@email}";><xsl:value-of 
select="@email"/></a>&gt;</xsl:if>
+  </dt>
+  <dd><xsl:apply-templates/></dd>
+</xsl:template>
+
+<xsl:template match="authors">
+  <dl>
     <xsl:apply-templates select="author"/>
-    </dl>
-  </xsl:template>
+  </dl>
+</xsl:template>
+
 </xsl:stylesheet>
 
 <!-- Local Variables: -->

Reply via email to