Skip to content

Instantly share code, notes, and snippets.

@tomschr
Last active March 20, 2025 15:28
Show Gist options
  • Save tomschr/a52da941f370c848ff3a00f1b901e4b8 to your computer and use it in GitHub Desktop.
Save tomschr/a52da941f370c848ff3a00f1b901e4b8 to your computer and use it in GitHub Desktop.
Convert OBS service file into DocBook refentry
<!--
Purpose:
Convert a service file from /usr/lib/obs/service/ into a DocBook 5
<refentry> structure
Parameters:
n/a
Input:
A service file from /usr/lib/obs/service/
Output:
DocBook 5 document with <refentry> root element
Additional information:
https://tdg.docbook.org/tdg/5.2/refentry
Author: 2025, Tom Schraitle
-->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:d="http://docbook.org/ns/docbook"
xmlns="http://docbook.org/ns/docbook">
<xsl:output indent="yes"/>
<!-- General -->
<xsl:template match="*">
<xsl:message>WARNING: No rule for element <xsl:value-of select="local-name(.)"/>.</xsl:message>
</xsl:template>
<xsl:template match="service">
<refentry version="5.2">
<xsl:attribute name="xml:id">
<xsl:value-of select="translate(@name, ' .', '_')" />
</xsl:attribute>
<refnamediv>
<xsl:apply-templates select="summary|description" />
</refnamediv>
<refsection>
<title>Parameters</title>
<xsl:apply-templates select="*[not(self::summary|self::description)]" />
</refsection>
</refentry>
</xsl:template>
<xsl:template match="service/summary">
<refname>
<xsl:apply-templates />
</refname>
</xsl:template>
<xsl:template match="service/description">
<refpurpose>
<xsl:apply-templates />
</refpurpose>
</xsl:template>
<xsl:template match="parameter">
<refsection>
<title><xsl:value-of select="@name" /></title>
<xsl:apply-templates select="description"/>
<xsl:apply-templates select="allowedvalue[1]" mode="allowedvalue"/>
<xsl:apply-templates select="*[not(self::description | self::allowedvalue)]" />
</refsection>
</xsl:template>
<xsl:template match="parameter/description">
<para>
<xsl:apply-templates />
</para>
</xsl:template>
<xsl:template match="parameter/allowedvalue" />
<xsl:template match="parameter/allowedvalue[1]" mode="allowedvalue" priority="2">
<para>Allowed values are:</para>
<itemizedlist>
<listitem>
<para><xsl:value-of select="normalize-space(.)"/></para>
</listitem>
<xsl:apply-templates select="following-sibling::allowedvalue" mode="allowedvalue"/>
</itemizedlist>
</xsl:template>
<xsl:template match="parameter/allowedvalue" mode="allowedvalue">
<listitem>
<para><xsl:value-of select="normalize-space(.)"/></para>
</listitem>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment