From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1255132-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(No client certificate requested)
	by finch.gentoo.org (Postfix) with ESMTPS id 340D51382C5
	for <garchives@archives.gentoo.org>; Thu, 25 Feb 2021 19:30:16 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 53E6EE09CF;
	Thu, 25 Feb 2021 19:30:15 +0000 (UTC)
Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 382EBE09CF
	for <gentoo-commits@lists.gentoo.org>; Thu, 25 Feb 2021 19:30:15 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 27494340CA2
	for <gentoo-commits@lists.gentoo.org>; Thu, 25 Feb 2021 19:30:11 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 84507478
	for <gentoo-commits@lists.gentoo.org>; Thu, 25 Feb 2021 19:30:09 +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: <1614279972.a3f7286741bd7511d25e174037ee7d23e4d38fa8.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: a3f7286741bd7511d25e174037ee7d23e4d38fa8
X-VCS-Branch: master
Date: Thu, 25 Feb 2021 19:30:09 +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: 768f7e67-4ebb-4a61-b757-1822225cdd59
X-Archives-Hash: d6f829d2c8b291402e206703bba5e716

commit:     a3f7286741bd7511d25e174037ee7d23e4d38fa8
Author:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
AuthorDate: Mon Feb 22 22:02:18 2021 +0000
Commit:     Ulrich Müller <ulm <AT> gentoo <DOT> org>
CommitDate: Thu Feb 25 19:06:12 2021 +0000
URL:        https://gitweb.gentoo.org/proj/devmanual.git/commit/?id=a3f72867

devbook.xsl: Remove code duplication in section templates

HTML output is identical.

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

 devbook.xsl | 54 ++++++++++++++++--------------------------------------
 1 file changed, 16 insertions(+), 38 deletions(-)

diff --git a/devbook.xsl b/devbook.xsl
index 003f7ed..ec02aa4 100644
--- a/devbook.xsl
+++ b/devbook.xsl
@@ -25,47 +25,25 @@
 
   <xsl:template match="chapter">
     <h1 class="first-header"><xsl:apply-templates select="title"/></h1>
-    <xsl:apply-templates select="(body|section)"/>
+    <xsl:apply-templates select="*[not(self::title)]"/>
   </xsl:template>
 
-  <xsl:template match="section">
-    <div class="section">
-      <xsl:variable name="anchor">
-        <xsl:call-template name="convert-to-anchor">
-          <xsl:with-param name="data" select="title"/>
-        </xsl:call-template>
-      </xsl:variable>
-
-      <h2 id="{$anchor}"><xsl:apply-templates select="title"/></h2>
-      <xsl:apply-templates select="(body|subsection)"/>
-    </div>
-  </xsl:template>
-
-  <xsl:template match="subsection">
-    <div class="section">
-      <xsl:variable name="anchor">
-        <xsl:call-template name="convert-to-anchor">
-          <xsl:with-param name="data" select="title"/>
-        </xsl:call-template>
-      </xsl:variable>
-
-      <h3 id="{$anchor}"><xsl:apply-templates select="title"/></h3>
-      <xsl:apply-templates select="(body|subsubsection)"/>
-    </div>
-  </xsl:template>
-
-  <xsl:template match="subsubsection">
+  <xsl:template match="section|subsection|subsubsection">
+    <xsl:variable name="level">
+      <xsl:value-of select="number(starts-with(local-name(), 'sub'))
+        + number(starts-with(local-name(), 'subsub')) + 2"/>
+    </xsl:variable>
+    <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:variable name="anchor">
-        <xsl:call-template name="convert-to-anchor">
-          <xsl:with-param name="data" select="title"/>
-        </xsl:call-template>
-      </xsl:variable>
-
-      <h4 id="{$anchor}"><xsl:apply-templates select="title"/></h4>
-      <xsl:apply-templates select="(body)"/>
-
-      <!-- If you need, change here to add more nesting levels -->
+      <xsl:element name="h{$level}">
+        <xsl:attribute name="id"><xsl:value-of select="$anchor"/></xsl:attribute>
+        <xsl:apply-templates select="title"/>
+      </xsl:element>
+      <xsl:apply-templates select="*[not(self::title)]"/>
     </div>
   </xsl:template>