[PATCH 2/5] docs: xsl: Don't format empty sections in API manual

Peter Krempa pkrempa at redhat.com
Thu Nov 3 12:33:12 UTC 2022


The LXC module has no exported 'Types' but the XSL template which
generates the 'libvirt-libvirt-lxc.html' page would try to format it
anyways. This would result in an empty non-pair version of the '<pre>'
tag to be used in the page, which didn't render well with modern
browsers for some reason. All following sections would become children
of the non-pair <pre>.

Fix the XSL template to not generate empty 'Types' or 'Functions'
sections similarly to how we do with 'Macros'.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 docs/newapi.xsl | 48 ++++++++++++++++++++++++++++--------------------
 1 file changed, 28 insertions(+), 20 deletions(-)

diff --git a/docs/newapi.xsl b/docs/newapi.xsl
index d48b1fbecd..7b0085930f 100644
--- a/docs/newapi.xsl
+++ b/docs/newapi.xsl
@@ -756,18 +756,22 @@
             </xsl:apply-templates>
           </pre>
         </xsl:if>
-        <h3><a href="#types">Types</a></h3>
-        <pre class="api">
-          <xsl:apply-templates select="exports[@type='typedef']" mode="toc">
-            <xsl:sort select='@symbol'/>
-          </xsl:apply-templates>
-        </pre>
-        <h3><a href="#functions">Functions</a></h3>
-        <pre class="api">
-          <xsl:apply-templates select="exports[@type='function']" mode="toc">
-            <xsl:sort select='@symbol'/>
-          </xsl:apply-templates>
-        </pre>
+        <xsl:if test="count(exports[@type='typedef']) > 0">
+          <h3><a href="#types">Types</a></h3>
+          <pre class="api">
+            <xsl:apply-templates select="exports[@type='typedef']" mode="toc">
+              <xsl:sort select='@symbol'/>
+            </xsl:apply-templates>
+          </pre>
+        </xsl:if>
+        <xsl:if test="count(exports[@type='function']) > 0">
+          <h3><a href="#functions">Functions</a></h3>
+          <pre class="api">
+            <xsl:apply-templates select="exports[@type='function']" mode="toc">
+              <xsl:sort select='@symbol'/>
+            </xsl:apply-templates>
+          </pre>
+        </xsl:if>

         <h2>Description</h2>

@@ -777,14 +781,18 @@
             <xsl:sort select='@symbol'/>
           </xsl:apply-templates>
         </xsl:if>
-        <h3><a id="types">Types</a></h3>
-        <xsl:apply-templates select="exports[@type='typedef']">
-          <xsl:sort select='@symbol'/>
-        </xsl:apply-templates>
-        <h3><a id="functions">Functions</a></h3>
-        <xsl:apply-templates select="exports[@type='function']">
-          <xsl:sort select='@symbol'/>
-        </xsl:apply-templates>
+        <xsl:if test="count(exports[@type='typedef']) > 0">
+          <h3><a id="types">Types</a></h3>
+          <xsl:apply-templates select="exports[@type='typedef']">
+            <xsl:sort select='@symbol'/>
+          </xsl:apply-templates>
+        </xsl:if>
+        <xsl:if test="count(exports[@type='function']) > 0">
+          <h3><a id="functions">Functions</a></h3>
+          <xsl:apply-templates select="exports[@type='function']">
+            <xsl:sort select='@symbol'/>
+          </xsl:apply-templates>
+        </xsl:if>
       </body>
     </html>
   </xsl:template>
-- 
2.37.3



More information about the libvir-list mailing list