You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

187 lines
6.4 KiB

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet version="1.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:str="http://exslt.org/strings"
  5. xmlns:xlink="http://www.w3.org/1999/xlink"
  6. xmlns="http://docbook.org/ns/docbook"
  7. extension-element-prefixes="str"
  8. >
  9. <xsl:output method='xml' encoding="UTF-8" />
  10. <xsl:param name="revision" />
  11. <xsl:template match="/expr/list">
  12. <variablelist>
  13. <xsl:for-each select="attrs">
  14. <varlistentry>
  15. <term>
  16. <option>
  17. <xsl:for-each select="attr[@name = 'name']/string">
  18. <xsl:value-of select="@value" />
  19. <xsl:if test="position() != last()">.</xsl:if>
  20. </xsl:for-each>
  21. </option>
  22. </term>
  23. <listitem>
  24. <para>
  25. <xsl:value-of disable-output-escaping="yes"
  26. select="attr[@name = 'description']/string/@value" />
  27. </para>
  28. <para>
  29. <emphasis>Default:</emphasis>
  30. <xsl:text> </xsl:text>
  31. <xsl:choose>
  32. <xsl:when test="attr[@name = 'default']">
  33. <literal>
  34. <xsl:apply-templates select="attr[@name = 'default']" />
  35. </literal>
  36. </xsl:when>
  37. <xsl:otherwise>
  38. none
  39. </xsl:otherwise>
  40. </xsl:choose>
  41. </para>
  42. <xsl:if test="attr[@name = 'example']">
  43. <para>
  44. <emphasis>Example:</emphasis>
  45. <xsl:text> </xsl:text>
  46. <xsl:choose>
  47. <xsl:when test="attr[@name = 'example']/attrs[attr[@name = '_type' and string[@value = 'literalExample']]]">
  48. <programlisting><xsl:value-of select="attr[@name = 'example']/attrs/attr[@name = 'text']/string/@value" /></programlisting>
  49. </xsl:when>
  50. <xsl:otherwise>
  51. <literal>
  52. <xsl:apply-templates select="attr[@name = 'example']" />
  53. </literal>
  54. </xsl:otherwise>
  55. </xsl:choose>
  56. </para>
  57. </xsl:if>
  58. <xsl:if test="count(attr[@name = 'declarations']/list/*) != 0">
  59. <para>
  60. <emphasis>Declared by:</emphasis>
  61. </para>
  62. <xsl:apply-templates select="attr[@name = 'declarations']" />
  63. </xsl:if>
  64. <xsl:if test="count(attr[@name = 'definitions']/list/*) != 0">
  65. <para>
  66. <emphasis>Defined by:</emphasis>
  67. </para>
  68. <xsl:apply-templates select="attr[@name = 'definitions']" />
  69. </xsl:if>
  70. </listitem>
  71. </varlistentry>
  72. </xsl:for-each>
  73. </variablelist>
  74. </xsl:template>
  75. <xsl:template match="string">
  76. <!-- !!! escaping -->
  77. <xsl:text>"</xsl:text><xsl:value-of select="str:replace(str:replace(str:replace(@value, '\', '\\'), '&quot;', '\&quot;'), '&#010;', '\n')" /><xsl:text>"</xsl:text>
  78. </xsl:template>
  79. <xsl:template match="int">
  80. <xsl:value-of select="@value" />
  81. </xsl:template>
  82. <xsl:template match="bool[@value = 'true']">
  83. <xsl:text>true</xsl:text>
  84. </xsl:template>
  85. <xsl:template match="bool[@value = 'false']">
  86. <xsl:text>false</xsl:text>
  87. </xsl:template>
  88. <xsl:template match="list">
  89. [
  90. <xsl:for-each select="*">
  91. <xsl:apply-templates select="." />
  92. <xsl:text> </xsl:text>
  93. </xsl:for-each>
  94. ]
  95. </xsl:template>
  96. <xsl:template match="attrs">
  97. {
  98. <xsl:for-each select="attr">
  99. <xsl:value-of select="@name" />
  100. <xsl:text> = </xsl:text>
  101. <xsl:apply-templates select="*" /><xsl:text>; </xsl:text>
  102. </xsl:for-each>
  103. }
  104. </xsl:template>
  105. <xsl:template match="derivation">
  106. <xsl:choose>
  107. <xsl:when test="attr[@name = 'url']/string/@value">
  108. <replaceable>(download of <xsl:value-of select="attr[@name = 'url']/string/@value" />)</replaceable>
  109. </xsl:when>
  110. <xsl:otherwise>
  111. <replaceable>(build of <xsl:value-of select="attr[@name = 'name']/string/@value" />)</replaceable>
  112. </xsl:otherwise>
  113. </xsl:choose>
  114. </xsl:template>
  115. <xsl:template match="attr[@name = 'declarations' or @name = 'definitions']">
  116. <simplelist>
  117. <xsl:for-each select="list/string">
  118. <member><filename>
  119. <!-- Hyperlink the filename either to the NixOS Subversion
  120. repository (if it’s a module and we have a revision number),
  121. or to the local filesystem. -->
  122. <xsl:choose>
  123. <xsl:when test="$revision != 'local' and contains(@value, '/modules/')">
  124. <xsl:attribute name="xlink:href">https://github.com/NixOS/nixos/blob/<xsl:value-of select="$revision"/>/modules/<xsl:value-of select="substring-after(@value, '/modules/')"/></xsl:attribute>
  125. </xsl:when>
  126. <xsl:when test="$revision != 'local' and contains(@value, 'nixops') and contains(@value, '/nix/')">
  127. <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>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <xsl:attribute name="xlink:href">file://<xsl:value-of select="@value"/></xsl:attribute>
  131. </xsl:otherwise>
  132. </xsl:choose>
  133. <!-- Print the filename and make it user-friendly by replacing the
  134. /nix/store/<hash> prefix by the default location of nixos
  135. sources. -->
  136. <xsl:choose>
  137. <xsl:when test="contains(@value, '/modules/')">
  138. &lt;nixos/modules/<xsl:value-of select="substring-after(@value, '/modules/')"/>&gt;
  139. </xsl:when>
  140. <xsl:when test="contains(@value, 'nixops') and contains(@value, '/nix/')">
  141. &lt;nixops/<xsl:value-of select="substring-after(@value, '/nix/')"/>&gt;
  142. </xsl:when>
  143. <xsl:otherwise>
  144. <xsl:value-of select="@value" />
  145. </xsl:otherwise>
  146. </xsl:choose>
  147. </filename></member>
  148. </xsl:for-each>
  149. </simplelist>
  150. </xsl:template>
  151. </xsl:stylesheet>