From: "Ulrich Müller" <ulm@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/devmanual:master commit in: /
Date: Mon, 28 Oct 2024 16:19:54 +0000 (UTC) [thread overview]
Message-ID: <1730021962.448d00f8e1f8265fed716f9b5090ef6f7524d56e.ulm@gentoo> (raw)
commit: 448d00f8e1f8265fed716f9b5090ef6f7524d56e
Author: Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Sat Oct 26 20:33:29 2024 +0000
Commit: Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Sun Oct 27 09:39:22 2024 +0000
URL: https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=448d00f8
devbook.xsl: Rework templates for previous/next node
- Separate finding the node from HTML formatting.
- Determine the absolute parent path from the path of our own @self
attribute, rather than from the parent document's @self attribute.
- Get the first node from the following-sibling or preceding-sibling
axis directly, instead of laboriously calculating its index.
Signed-off-by: Ulrich Müller <ulm <AT> gentoo.org>
devbook.xsl | 151 +++++++++++++++++++++++++-----------------------------------
1 file changed, 62 insertions(+), 89 deletions(-)
diff --git a/devbook.xsl b/devbook.xsl
index 0a3d7d8..a10f5ab 100644
--- a/devbook.xsl
+++ b/devbook.xsl
@@ -747,7 +747,7 @@
</html>
</xsl:template>
-<xsl:template name="findNext">
+<xsl:template name="next-node">
<xsl:param name="self" select="/guide/@self"/>
<xsl:choose>
<!-- To find the "next" node:
@@ -759,57 +759,29 @@
* End at the root item if needed.
-->
<xsl:when test="count(/guide/include) > 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:value-of select="/guide/include[1]/@href"/>
</xsl:when>
- <xsl:otherwise>
+ <xsl:when test="$self != ''">
<!-- 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"/>
+ <xsl:variable name="parent" select="substring($self, 1, string-length($self) - string-length($path_self))"/>
<!-- 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:variable name="following" select="document(concat($parent, 'text.xml'))
+ /guide/include[@href=$path_self]/following-sibling::include[1]"/>
+ <xsl:text>../</xsl:text>
<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">
- <!-- Compute a relative path for the link. -->
- <xsl:variable name="path_rel">
- <xsl:call-template name="relative-path">
- <xsl:with-param name="path" select="$parentItem_next"/>
- <xsl:with-param name="self" select="/guide/@self"/>
- </xsl:call-template>
- </xsl:variable>
- <a class="w-250 text-center" href="{concat($path_rel, 'index.html')}">
- <span class="truncated-text d-inline-block max-w-200 mr-2">
- <xsl:value-of select="document(concat($parentItem_next, 'text.xml'))/guide/chapter[1]/title"/>
- </span>
- <span class="fa fa-arrow-right"/>
- </a>
+ <!-- If we have an item after us, we need not recurse any further... -->
+ <xsl:when test="$following">
+ <xsl:value-of select="$following/@href"/>
</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_fixed">
- <xsl:for-each select="str:tokenize($self, '/')[position() < last()]">
- <xsl:value-of select="concat(., '/')"/>
- </xsl:for-each>
- </xsl:variable>
- <xsl:call-template name="findNext">
- <xsl:with-param name="self" select="$relative_path_fixed"/>
+ <xsl:call-template name="next-node">
+ <xsl:with-param name="self" select="$parent"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
- </xsl:otherwise>
+ </xsl:when>
</xsl:choose>
</xsl:template>
@@ -831,60 +803,61 @@
</xsl:choose>
</xsl:template>
-<xsl:template name="findPrevious">
- <xsl:choose>
+<xsl:template name="previous-node">
+ <xsl:variable name="self" select="/guide/@self"/>
+ <xsl:if test="$self != ''">
<!-- 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>
- <!-- Turn the absolute path we have into a relative path so we can find
- ourselves in the parent -->
- <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 > 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="$parentItem_next"/>
- </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('../', $myItem_path, '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, 'text.xml'))/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>
+ <!-- Turn the absolute path we have 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="parent" select="substring($self, 1, string-length($self) - string-length($path_self))"/>
+ <!-- Note that index 1 refers to the immediately preceding sibling looking
+ back from the context node, not the first sibling in document order. -->
+ <xsl:variable name="preceding" select="document(concat($parent, 'text.xml'))
+ /guide/include[@href=$path_self]/preceding-sibling::include[1]"/>
+ <xsl:text>../</xsl:text>
+ <xsl:if test="$preceding">
+ <xsl:call-template name="getLastNode">
+ <xsl:with-param name="root" select="$parent"/>
+ <xsl:with-param name="path" select="$preceding/@href"/>
+ </xsl:call-template>
+ </xsl:if>
+ </xsl:if>
+</xsl:template>
+
+<xsl:template name="findNext">
+ <xsl:variable name="next">
+ <xsl:call-template name="next-node"/>
+ </xsl:variable>
+ <a class="w-250 text-center" href="{concat($next, 'index.html')}">
+ <span class="truncated-text d-inline-block max-w-200 mr-2">
+ <xsl:value-of select="document(concat(/guide/@self, $next, 'text.xml'))/guide/chapter[1]/title"/>
+ </span>
+ <span class="fa fa-arrow-right"/>
+ </a>
+</xsl:template>
+
+<xsl:template name="findPrevious">
+ <xsl:variable name="previous">
+ <xsl:call-template name="previous-node"/>
+ </xsl:variable>
+ <xsl:variable name="link">
+ <xsl:choose>
+ <xsl:when test="$previous = ''">#</xsl:when> <!-- root node refers to itself -->
+ <xsl:otherwise><xsl:value-of select="concat($previous, 'index.html')"/></xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <a class="w-250 text-center" href="{$link}">
+ <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, $previous, 'text.xml'))/guide/chapter[1]/title"/>
+ </span>
+ </a>
</xsl:template>
<xsl:template name="printParentDocs">
next reply other threads:[~2024-10-28 16:19 UTC|newest]
Thread overview: 213+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-28 16:19 Ulrich Müller [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-11-12 18:51 [gentoo-commits] proj/devmanual:master commit in: / Ulrich Müller
2024-11-09 6:58 Ulrich Müller
2024-11-06 20:00 Ulrich Müller
2024-11-05 22:13 Ulrich Müller
2024-11-01 20:01 Ulrich Müller
2024-11-01 17:27 Ulrich Müller
2024-11-01 11:20 Ulrich Müller
2024-11-01 11:20 Ulrich Müller
2024-10-31 18:59 Ulrich Müller
2024-10-31 11:08 Ulrich Müller
2024-10-31 11:08 Ulrich Müller
2024-10-27 7:55 Ulrich Müller
2024-07-30 14:30 Ulrich Müller
2024-06-11 16:24 Ulrich Müller
2024-06-10 15:41 Ulrich Müller
2024-05-08 6:43 Ulrich Müller
2024-04-22 18:19 Ulrich Müller
2024-03-23 7:10 Ulrich Müller
2024-01-28 17:40 Ulrich Müller
2023-11-23 17:24 Ulrich Müller
2023-11-05 16:44 Ulrich Müller
2023-11-02 17:08 Ulrich Müller
2023-11-02 17:06 Ulrich Müller
2023-11-02 17:06 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-31 20:03 Ulrich Müller
2023-10-22 11:44 Ulrich Müller
2023-10-22 11:44 Ulrich Müller
2023-10-05 20:43 Ulrich Müller
2022-06-24 10:51 Ulrich Müller
2022-06-22 14:35 Ulrich Müller
2022-06-17 8:00 Ulrich Müller
2022-06-10 17:20 Ulrich Müller
2022-01-24 18:16 Ulrich Müller
2022-01-19 11:30 Ulrich Müller
2022-01-16 21:52 Ulrich Müller
2021-10-11 10:53 Ulrich Müller
2021-10-10 10:34 Ulrich Müller
2021-10-10 10:34 Ulrich Müller
2021-09-08 17:52 Ulrich Müller
2021-09-08 17:52 Ulrich Müller
2021-07-14 12:27 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 19:51 Ulrich Müller
2021-03-10 18:39 Ulrich Müller
2021-03-07 17:40 Ulrich Müller
2021-03-03 19:08 Ulrich Müller
2021-02-27 15:47 Ulrich Müller
2021-02-25 23:49 Ulrich Müller
2021-02-25 19:30 Ulrich Müller
2021-02-25 19:30 Ulrich Müller
2021-02-24 19:36 Ulrich Müller
2021-02-06 10:39 Ulrich Müller
2021-01-25 10:34 Ulrich Müller
2021-01-18 12:17 Ulrich Müller
2021-01-17 22:09 Ulrich Müller
2020-08-28 17:46 Ulrich Müller
2020-03-06 16:30 Ulrich Müller
2020-03-03 8:30 Ulrich Müller
2020-03-03 8:18 Ulrich Müller
2020-03-02 10:23 Ulrich Müller
2020-03-02 10:23 Ulrich Müller
2020-02-28 7:20 Ulrich Müller
2020-02-28 7:20 Ulrich Müller
2020-02-28 7:17 Ulrich Müller
2020-02-28 7:15 Ulrich Müller
2020-02-28 7:15 Ulrich Müller
2020-02-28 7:15 Ulrich Müller
2020-02-26 20:41 Ulrich Müller
2020-02-26 20:41 Ulrich Müller
2020-02-26 18:59 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-26 18:53 Ulrich Müller
2020-02-16 13:16 Ulrich Müller
2020-02-11 11:30 Ulrich Müller
2020-02-10 17:31 Ulrich Müller
2020-02-07 14:01 Ulrich Müller
2020-02-07 5:34 Ulrich Müller
2020-02-06 20:53 Ulrich Müller
2020-02-03 10:06 Ulrich Müller
2020-02-03 0:07 Ulrich Müller
2020-02-03 0:07 Ulrich Müller
2020-02-03 0:07 Ulrich Müller
2020-01-30 13:45 Brian Evans
2020-01-27 20:44 Ulrich Müller
2020-01-27 19:58 Ulrich Müller
2020-01-27 19:58 Ulrich Müller
2020-01-22 18:24 Ulrich Müller
2020-01-21 21:53 Ulrich Müller
2020-01-16 18:53 Ulrich Müller
2020-01-15 7:06 Ulrich Müller
2020-01-14 8:15 Ulrich Müller
2020-01-12 9:23 Ulrich Müller
2020-01-09 7:34 Ulrich Müller
2020-01-09 7:34 Ulrich Müller
2020-01-02 13:38 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2020-01-02 12:54 Ulrich Müller
2019-12-26 21:36 Ulrich Müller
2019-12-26 20:33 Ulrich Müller
2019-12-26 17:06 Ulrich Müller
2019-12-26 16:47 Ulrich Müller
2019-12-21 5:19 Ulrich Müller
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-19 21:02 Göktürk Yüksek
2019-12-14 10:46 Ulrich Müller
2019-12-10 8:47 Ulrich Müller
2019-12-10 8:47 Ulrich Müller
2019-12-07 22:05 Ulrich Müller
2019-11-26 3:05 Göktürk Yüksek
2019-03-22 18:51 Brian Evans
2019-03-22 18:51 Brian Evans
2019-03-19 19:02 Brian Evans
2019-03-19 17:11 Brian Evans
2018-01-03 5:57 [gentoo-commits] proj/devmanual:codesample-indent-fix " Göktürk Yüksek
2018-01-03 21:59 ` [gentoo-commits] proj/devmanual:master " Göktürk Yüksek
2017-02-05 22:41 Ulrich Müller
2016-10-31 1:21 Göktürk Yüksek
2016-10-28 17:15 Ulrich Müller
2016-10-06 22:09 Mike Gilbert
2016-06-15 18:46 Ulrich Müller
2016-05-15 11:48 Ulrich Müller
2016-05-15 11:48 Ulrich Müller
2016-04-02 8:54 Ulrich Müller
2016-02-05 8:41 Ulrich Müller
2016-01-01 21:59 NP Hardass
2015-09-05 15:48 Markos Chandras
2015-08-27 6:50 Justin Lecher
2015-08-21 6:36 Justin Lecher
2015-08-21 6:36 Justin Lecher
2015-08-20 7:06 Justin Lecher
2015-08-20 7:04 Justin Lecher
2015-08-18 11:47 Justin Lecher
2015-08-09 12:39 Justin Lecher
2015-08-09 12:39 Justin Lecher
2015-08-09 9:30 Justin Lecher
2015-08-09 9:30 Justin Lecher
2015-07-22 1:15 Jorge Manuel B. S. Vicetto
2015-06-17 12:05 Ulrich Müller
2015-06-01 18:41 Ulrich Müller
2015-06-01 15:38 Ulrich Müller
2015-05-31 10:45 Markus Meier
2015-05-31 10:45 Markus Meier
2015-03-30 18:21 Markos Chandras
2015-03-11 18:26 Markos Chandras
2015-02-15 9:54 Markos Chandras
2015-01-17 9:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-14 18:07 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-11-08 12:27 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:36 Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-10-18 17:35 Markos Chandras
2014-07-24 18:06 ` Markos Chandras
2014-07-24 18:06 Markos Chandras
2014-10-18 17:35 ` Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-16 10:24 Markos Chandras
2014-03-08 14:53 Markos Chandras
2014-01-05 12:35 Markos Chandras
2014-01-04 11:23 Markos Chandras
2014-01-03 18:32 Markos Chandras
2013-09-26 7:41 Markos Chandras
2013-09-21 12:23 Markos Chandras
2013-09-21 12:23 Markos Chandras
2013-07-25 8:28 Justin Lecher
2013-05-19 8:38 Markos Chandras
2013-05-15 12:57 Dirkjan Ochtman
2013-05-12 19:25 Markos Chandras
2013-05-12 15:06 Markos Chandras
2013-05-11 19:02 Markos Chandras
2012-10-12 17:44 Ulrich Mueller
2012-08-08 19:23 Markos Chandras
2012-03-18 0:16 Markos Chandras
2011-12-20 12:39 Torsten Veller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1730021962.448d00f8e1f8265fed716f9b5090ef6f7524d56e.ulm@gentoo \
--to=ulm@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox