From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <gentoo-commits+bounces-1684183-garchives=archives.gentoo.org@lists.gentoo.org> Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 0A28D158042 for <garchives@archives.gentoo.org>; Mon, 28 Oct 2024 16:19:58 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 34BB9E0887; Mon, 28 Oct 2024 16:19:57 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 1D925E0887 for <gentoo-commits@lists.gentoo.org>; Mon, 28 Oct 2024 16:19:57 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 4BE523430CA for <gentoo-commits@lists.gentoo.org>; Mon, 28 Oct 2024 16:19:56 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 5F9C71626 for <gentoo-commits@lists.gentoo.org>; Mon, 28 Oct 2024 16:19:54 +0000 (UTC) From: "Ulrich Müller" <ulm@gentoo.org> To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Ulrich Müller" <ulm@gentoo.org> Message-ID: <1730021962.448d00f8e1f8265fed716f9b5090ef6f7524d56e.ulm@gentoo> Subject: [gentoo-commits] proj/devmanual:master commit in: / X-VCS-Repository: proj/devmanual X-VCS-Files: devbook.xsl X-VCS-Directories: / X-VCS-Committer: ulm X-VCS-Committer-Name: Ulrich Müller X-VCS-Revision: 448d00f8e1f8265fed716f9b5090ef6f7524d56e X-VCS-Branch: master Date: Mon, 28 Oct 2024 16:19:54 +0000 (UTC) Precedence: bulk List-Post: <mailto:gentoo-commits@lists.gentoo.org> List-Help: <mailto:gentoo-commits+help@lists.gentoo.org> List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org> List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org> List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org> X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: d4a0f604-6906-4590-b1c0-16662c3e0e8c X-Archives-Hash: ca3cf1b1643f6d7f43848235f2a29c48 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">