2007-01-23 11:52:51 +01:00
|
|
|
|
<?xml version="1.0"?>
|
|
|
|
|
|
|
|
|
|
<xsl:stylesheet version="1.0"
|
|
|
|
|
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
|
|
|
|
xmlns:str="http://exslt.org/strings"
|
2007-01-23 12:06:31 +01:00
|
|
|
|
xmlns:xlink="http://www.w3.org/1999/xlink"
|
nixos: Split paras by \n\n in option descriptions
What annoyed me for a long time was the fact, that in order to break
into a new paragraph, you need to insert </para><para> in the
description attribute of an option.
Now we will automatically create <para/> elements for every block that
is separated by two consecutive newlines.
I first tried to do this within options-to-docbook.xsl, but it turns
out[1] that this isn't directly possible with XSLT 1.0, so I added
another XSLT file that postprocesses the option descriptions that are
now enclosed in <nixos:option-description/> by options-to-docbook.xsl.
The splitting itself is a bit more involved, because we can't simply
split on every \n\n because we'd also split text nodes of elements, for
example:
<screen><![CDATA[
one line
another one
]]></screen>
This would create one <para/> element for "one line" and another for
"another line", which we obviously don't want because <screen/> is used
to display verbatim contents of what a user is seeing on the screen.
So what we do instead is splitting *only* the top-level text nodes
within the outermost <para/> and leave all elements as-is. If there are
more than one <para/> elements at the top-level, we simply don't process
it at all, because the description then already contains </para><para>.
https://www.mhonarc.org/archive/html/xsl-list/2012-09/msg00319.html
Signed-off-by: aszlig <aszlig@nix.build>
Cc: @edolstra, @domenkozar
2018-09-02 05:05:34 +02:00
|
|
|
|
xmlns:nixos="tag:nixos.org"
|
2007-01-23 11:52:51 +01:00
|
|
|
|
xmlns="http://docbook.org/ns/docbook"
|
|
|
|
|
extension-element-prefixes="str"
|
|
|
|
|
>
|
|
|
|
|
|
|
|
|
|
<xsl:output method='xml' encoding="UTF-8" />
|
|
|
|
|
|
2009-10-06 01:47:50 +02:00
|
|
|
|
<xsl:param name="revision" />
|
2022-05-01 21:50:51 +02:00
|
|
|
|
<xsl:param name="documentType" />
|
2016-06-03 16:55:01 +02:00
|
|
|
|
<xsl:param name="program" />
|
2022-06-27 17:27:24 +02:00
|
|
|
|
<xsl:param name="variablelistId" />
|
2022-09-29 12:34:06 +02:00
|
|
|
|
<xsl:param name="optionIdPrefix" />
|
2009-10-06 01:47:50 +02:00
|
|
|
|
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
2007-01-23 11:52:51 +01:00
|
|
|
|
<xsl:template match="/expr/list">
|
2022-05-01 21:50:51 +02:00
|
|
|
|
<xsl:choose>
|
|
|
|
|
<xsl:when test="$documentType = 'appendix'">
|
|
|
|
|
<appendix xml:id="appendix-configuration-options">
|
|
|
|
|
<title>Configuration Options</title>
|
|
|
|
|
<xsl:call-template name="variable-list"/>
|
|
|
|
|
</appendix>
|
|
|
|
|
</xsl:when>
|
|
|
|
|
<xsl:otherwise>
|
|
|
|
|
<xsl:call-template name="variable-list"/>
|
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
<xsl:template name="variable-list">
|
2022-06-27 17:27:24 +02:00
|
|
|
|
<variablelist>
|
|
|
|
|
<xsl:attribute name="id" namespace="http://www.w3.org/XML/1998/namespace"><xsl:value-of select="$variablelistId"/></xsl:attribute>
|
2007-01-23 11:52:51 +01:00
|
|
|
|
<xsl:for-each select="attrs">
|
2022-05-13 09:00:06 +02:00
|
|
|
|
<xsl:variable name="id" select="
|
2022-09-29 12:34:06 +02:00
|
|
|
|
concat($optionIdPrefix,
|
2022-05-16 22:53:23 +02:00
|
|
|
|
translate(
|
2022-05-13 09:00:06 +02:00
|
|
|
|
attr[@name = 'name']/string/@value,
|
2022-05-16 22:53:23 +02:00
|
|
|
|
'*< >[]:',
|
|
|
|
|
'_______'
|
|
|
|
|
))" />
|
2007-01-23 11:52:51 +01:00
|
|
|
|
<varlistentry>
|
2014-04-14 10:19:30 +02:00
|
|
|
|
<term xlink:href="#{$id}">
|
|
|
|
|
<xsl:attribute name="xml:id"><xsl:value-of select="$id"/></xsl:attribute>
|
2014-03-08 19:33:41 +01:00
|
|
|
|
<option>
|
2014-04-14 10:23:02 +02:00
|
|
|
|
<xsl:value-of select="attr[@name = 'name']/string/@value" />
|
2014-03-08 19:33:41 +01:00
|
|
|
|
</option>
|
2015-07-30 13:27:09 +02:00
|
|
|
|
</term>
|
|
|
|
|
|
|
|
|
|
<listitem>
|
|
|
|
|
|
nixos: Split paras by \n\n in option descriptions
What annoyed me for a long time was the fact, that in order to break
into a new paragraph, you need to insert </para><para> in the
description attribute of an option.
Now we will automatically create <para/> elements for every block that
is separated by two consecutive newlines.
I first tried to do this within options-to-docbook.xsl, but it turns
out[1] that this isn't directly possible with XSLT 1.0, so I added
another XSLT file that postprocesses the option descriptions that are
now enclosed in <nixos:option-description/> by options-to-docbook.xsl.
The splitting itself is a bit more involved, because we can't simply
split on every \n\n because we'd also split text nodes of elements, for
example:
<screen><![CDATA[
one line
another one
]]></screen>
This would create one <para/> element for "one line" and another for
"another line", which we obviously don't want because <screen/> is used
to display verbatim contents of what a user is seeing on the screen.
So what we do instead is splitting *only* the top-level text nodes
within the outermost <para/> and leave all elements as-is. If there are
more than one <para/> elements at the top-level, we simply don't process
it at all, because the description then already contains </para><para>.
https://www.mhonarc.org/archive/html/xsl-list/2012-09/msg00319.html
Signed-off-by: aszlig <aszlig@nix.build>
Cc: @edolstra, @domenkozar
2018-09-02 05:05:34 +02:00
|
|
|
|
<nixos:option-description>
|
|
|
|
|
<para>
|
|
|
|
|
<xsl:value-of disable-output-escaping="yes"
|
|
|
|
|
select="attr[@name = 'description']/string/@value" />
|
|
|
|
|
</para>
|
|
|
|
|
</nixos:option-description>
|
2015-07-30 13:27:09 +02:00
|
|
|
|
|
|
|
|
|
<xsl:if test="attr[@name = 'type']">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Type:</emphasis>
|
|
|
|
|
<xsl:text> </xsl:text>
|
2015-07-30 13:44:08 +02:00
|
|
|
|
<xsl:value-of select="attr[@name = 'type']/string/@value"/>
|
2015-07-30 13:36:57 +02:00
|
|
|
|
<xsl:if test="attr[@name = 'readOnly']/bool/@value = 'true'">
|
|
|
|
|
<xsl:text> </xsl:text>
|
|
|
|
|
<emphasis>(read only)</emphasis>
|
|
|
|
|
</xsl:if>
|
2015-07-30 13:27:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
|
|
<xsl:if test="attr[@name = 'default']">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Default:</emphasis>
|
|
|
|
|
<xsl:text> </xsl:text>
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:apply-templates select="attr[@name = 'default']/*" mode="top" />
|
2015-07-30 13:27:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
|
|
<xsl:if test="attr[@name = 'example']">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Example:</emphasis>
|
|
|
|
|
<xsl:text> </xsl:text>
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:apply-templates select="attr[@name = 'example']/*" mode="top" />
|
2015-07-30 13:27:09 +02:00
|
|
|
|
</para>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
2016-04-20 23:57:33 +02:00
|
|
|
|
<xsl:if test="attr[@name = 'relatedPackages']">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Related packages:</emphasis>
|
|
|
|
|
<xsl:text> </xsl:text>
|
|
|
|
|
<xsl:value-of disable-output-escaping="yes"
|
|
|
|
|
select="attr[@name = 'relatedPackages']/string/@value" />
|
|
|
|
|
</para>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
2015-07-30 13:27:09 +02:00
|
|
|
|
<xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Declared by:</emphasis>
|
|
|
|
|
</para>
|
|
|
|
|
<xsl:apply-templates select="attr[@name = 'declarations']" />
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
|
|
<xsl:if test="count(attr[@name = 'definitions']/list/*) != 0">
|
|
|
|
|
<para>
|
|
|
|
|
<emphasis>Defined by:</emphasis>
|
|
|
|
|
</para>
|
|
|
|
|
<xsl:apply-templates select="attr[@name = 'definitions']" />
|
|
|
|
|
</xsl:if>
|
|
|
|
|
|
|
|
|
|
</listitem>
|
2007-01-23 11:52:51 +01:00
|
|
|
|
|
|
|
|
|
</varlistentry>
|
|
|
|
|
|
|
|
|
|
</xsl:for-each>
|
|
|
|
|
|
|
|
|
|
</variablelist>
|
|
|
|
|
</xsl:template>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
|
|
|
|
|
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]" mode = "top">
|
2013-10-29 17:29:37 +01:00
|
|
|
|
<xsl:choose>
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:when test="contains(attr[@name = 'text']/string/@value, '
')">
|
|
|
|
|
<programlisting><xsl:value-of select="attr[@name = 'text']/string/@value" /></programlisting>
|
2013-10-29 17:29:37 +01:00
|
|
|
|
</xsl:when>
|
|
|
|
|
<xsl:otherwise>
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<literal><xsl:value-of select="attr[@name = 'text']/string/@value" /></literal>
|
2013-10-29 17:29:37 +01:00
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalDocBook']]]" mode = "top">
|
|
|
|
|
<xsl:value-of disable-output-escaping="yes" select="attr[@name = 'text']/string/@value" />
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<xsl:template match="string[contains(@value, '
')]" mode="top">
|
|
|
|
|
<programlisting>
|
|
|
|
|
<xsl:text>''
</xsl:text>
|
|
|
|
|
<xsl:value-of select='str:replace(str:replace(@value, "''", "'''"), "${", "''${")' />
|
|
|
|
|
<xsl:text>''</xsl:text>
|
|
|
|
|
</programlisting>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<xsl:template match="*" mode="top">
|
|
|
|
|
<literal><xsl:apply-templates select="." /></literal>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
2013-10-29 14:55:33 +01:00
|
|
|
|
<xsl:template match="null">
|
|
|
|
|
<xsl:text>null</xsl:text>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="string">
|
2013-10-29 16:52:40 +01:00
|
|
|
|
<xsl:choose>
|
|
|
|
|
<xsl:when test="(contains(@value, '"') or contains(@value, '\')) and not(contains(@value, '
'))">
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:text>''</xsl:text><xsl:value-of select='str:replace(str:replace(@value, "''", "'''"), "${", "''${")' /><xsl:text>''</xsl:text>
|
2013-10-29 16:52:40 +01:00
|
|
|
|
</xsl:when>
|
|
|
|
|
<xsl:otherwise>
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(str:replace(@value, '\', '\\'), '"', '\"'), '
', '\n'), '${', '\${')" /><xsl:text>"</xsl:text>
|
2013-10-29 16:52:40 +01:00
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="int">
|
|
|
|
|
<xsl:value-of select="@value" />
|
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="bool[@value = 'true']">
|
2007-11-21 15:39:52 +01:00
|
|
|
|
<xsl:text>true</xsl:text>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="bool[@value = 'false']">
|
2007-11-21 15:39:52 +01:00
|
|
|
|
<xsl:text>false</xsl:text>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="list">
|
|
|
|
|
[
|
|
|
|
|
<xsl:for-each select="*">
|
|
|
|
|
<xsl:apply-templates select="." />
|
|
|
|
|
<xsl:text> </xsl:text>
|
|
|
|
|
</xsl:for-each>
|
|
|
|
|
]
|
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2021-10-03 17:59:35 +02:00
|
|
|
|
<xsl:template match="attrs[attr[@name = '_type' and string[@value = 'literalExpression']]]">
|
2013-10-23 19:46:11 +02:00
|
|
|
|
<xsl:value-of select="attr[@name = 'text']/string/@value" />
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
2007-01-23 12:39:02 +01:00
|
|
|
|
<xsl:template match="attrs">
|
|
|
|
|
{
|
|
|
|
|
<xsl:for-each select="attr">
|
|
|
|
|
<xsl:value-of select="@name" />
|
|
|
|
|
<xsl:text> = </xsl:text>
|
2007-11-21 15:39:52 +01:00
|
|
|
|
<xsl:apply-templates select="*" /><xsl:text>; </xsl:text>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
</xsl:for-each>
|
|
|
|
|
}
|
|
|
|
|
</xsl:template>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
|
|
|
|
|
|
2021-11-18 23:00:03 +01:00
|
|
|
|
<xsl:template match="attrs[attr[@name = '_type' and string[@value = 'derivation']]]">
|
2013-10-30 16:19:07 +01:00
|
|
|
|
<replaceable>(build of <xsl:value-of select="attr[@name = 'name']/string/@value" />)</replaceable>
|
2007-01-23 12:39:02 +01:00
|
|
|
|
</xsl:template>
|
2009-09-18 17:10:37 +02:00
|
|
|
|
|
|
|
|
|
<xsl:template match="attr[@name = 'declarations' or @name = 'definitions']">
|
2009-10-06 01:15:06 +02:00
|
|
|
|
<simplelist>
|
2022-05-25 11:49:17 +02:00
|
|
|
|
<!--
|
|
|
|
|
Example:
|
|
|
|
|
opt.declarations = [ { name = "foo/bar.nix"; url = "https://github.com/....."; } ];
|
|
|
|
|
-->
|
|
|
|
|
<xsl:for-each select="list/attrs[attr[@name = 'name']]">
|
|
|
|
|
<member><filename>
|
|
|
|
|
<xsl:if test="attr[@name = 'url']">
|
|
|
|
|
<xsl:attribute name="xlink:href"><xsl:value-of select="attr[@name = 'url']/string/@value"/></xsl:attribute>
|
|
|
|
|
</xsl:if>
|
|
|
|
|
<xsl:value-of select="attr[@name = 'name']/string/@value"/>
|
|
|
|
|
</filename></member>
|
|
|
|
|
</xsl:for-each>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
When the declarations/definitions are raw strings,
|
|
|
|
|
fall back to hardcoded location logic, specific to Nixpkgs.
|
|
|
|
|
-->
|
2009-09-18 17:10:37 +02:00
|
|
|
|
<xsl:for-each select="list/string">
|
2009-10-06 01:47:50 +02:00
|
|
|
|
<member><filename>
|
|
|
|
|
<!-- Hyperlink the filename either to the NixOS Subversion
|
|
|
|
|
repository (if it’s a module and we have a revision number),
|
|
|
|
|
or to the local filesystem. -->
|
|
|
|
|
<xsl:choose>
|
2013-10-23 19:32:19 +02:00
|
|
|
|
<xsl:when test="not(starts-with(@value, '/'))">
|
|
|
|
|
<xsl:choose>
|
|
|
|
|
<xsl:when test="$revision = 'local'">
|
|
|
|
|
<xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/master/<xsl:value-of select="@value"/></xsl:attribute>
|
|
|
|
|
</xsl:when>
|
|
|
|
|
<xsl:otherwise>
|
|
|
|
|
<xsl:attribute name="xlink:href">https://github.com/NixOS/nixpkgs/blob/<xsl:value-of select="$revision"/>/<xsl:value-of select="@value"/></xsl:attribute>
|
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
2009-10-06 01:47:50 +02:00
|
|
|
|
</xsl:when>
|
2016-06-03 16:55:01 +02:00
|
|
|
|
<xsl:when test="$revision != 'local' and $program = 'nixops' and contains(@value, '/nix/')">
|
2013-06-18 09:34:30 +02:00
|
|
|
|
<xsl:attribute name="xlink:href">https://github.com/NixOS/nixops/blob/<xsl:value-of select="$revision"/>/nix/<xsl:value-of select="substring-after(@value, '/nix/')"/></xsl:attribute>
|
2012-06-08 23:10:11 +02:00
|
|
|
|
</xsl:when>
|
2009-10-06 01:47:50 +02:00
|
|
|
|
<xsl:otherwise>
|
|
|
|
|
<xsl:attribute name="xlink:href">file://<xsl:value-of select="@value"/></xsl:attribute>
|
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
2009-10-06 21:07:09 +02:00
|
|
|
|
<!-- Print the filename and make it user-friendly by replacing the
|
|
|
|
|
/nix/store/<hash> prefix by the default location of nixos
|
|
|
|
|
sources. -->
|
2009-10-06 11:53:19 +02:00
|
|
|
|
<xsl:choose>
|
2013-10-23 19:32:19 +02:00
|
|
|
|
<xsl:when test="not(starts-with(@value, '/'))">
|
|
|
|
|
<nixpkgs/<xsl:value-of select="@value"/>>
|
2009-10-06 11:53:19 +02:00
|
|
|
|
</xsl:when>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
<xsl:when test="contains(@value, 'nixops') and contains(@value, '/nix/')">
|
|
|
|
|
<nixops/<xsl:value-of select="substring-after(@value, '/nix/')"/>>
|
2012-06-08 23:10:11 +02:00
|
|
|
|
</xsl:when>
|
2009-10-06 11:53:19 +02:00
|
|
|
|
<xsl:otherwise>
|
|
|
|
|
<xsl:value-of select="@value" />
|
|
|
|
|
</xsl:otherwise>
|
|
|
|
|
</xsl:choose>
|
2009-10-06 01:47:50 +02:00
|
|
|
|
</filename></member>
|
2009-09-18 17:10:37 +02:00
|
|
|
|
</xsl:for-each>
|
2009-10-06 01:15:06 +02:00
|
|
|
|
</simplelist>
|
2013-06-18 09:34:30 +02:00
|
|
|
|
</xsl:template>
|
|
|
|
|
|
2014-08-09 16:21:33 +02:00
|
|
|
|
|
|
|
|
|
<xsl:template match="function">
|
|
|
|
|
<xsl:text>λ</xsl:text>
|
|
|
|
|
</xsl:template>
|
|
|
|
|
|
|
|
|
|
|
2007-01-23 11:52:51 +01:00
|
|
|
|
</xsl:stylesheet>
|