cuberef2cubescript.xslt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. Transforms the ../reference.xml document into a CubeScript document.
  4. Written by: Adrian 'driAn' Henke (of Rabid Viper Productions).
  5. You may be able to redistribute this content under specific
  6. conditions. Please read the licensing information, available
  7. at https://assault.cubers.net/docs/license.html for the
  8. conditions that would apply to what you may be redistributing.
  9. -->
  10. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:t="https://assault.cubers.net/docs/xml">
  11. <xsl:output method="text" encoding="ASCII"/>
  12. <!-- horizontal tab -->
  13. <xsl:variable name="indent">
  14. <xsl:text>&#09;</xsl:text>
  15. </xsl:variable>
  16. <!-- line feed, CRLF (dos/win) -->
  17. <xsl:variable name="newline">
  18. <xsl:text>&#13;&#10;</xsl:text>
  19. </xsl:variable>
  20. <xsl:template match="/t:cuberef">
  21. <xsl:text>// This CubeScript file has been automatically generated from AssaultCube's ./docs/reference.xml</xsl:text>
  22. <xsl:value-of select="$newline"/>
  23. <xsl:text>// DO NOT MODIFY THIS FILE - Instead, modify ./docs/reference.xml and generate this file automatically.</xsl:text>
  24. <xsl:value-of select="$newline"/>
  25. <xsl:text>// To generate this file automatically, please carefully read the comment at the top of reference.xml</xsl:text>
  26. <xsl:value-of select="$newline"/>
  27. <xsl:value-of select="$newline"/>
  28. <!-- sections -->
  29. <xsl:for-each select="t:sections/t:section">
  30. <xsl:text>docsection </xsl:text>
  31. <xsl:text>[</xsl:text>
  32. <xsl:value-of select="@name"/>
  33. <xsl:text>]</xsl:text>
  34. <xsl:value-of select="$newline"/>
  35. <!-- identifiers -->
  36. <xsl:for-each select="t:identifiers/*">
  37. <xsl:sort select="@name"/> <!-- always sort to avoid excessive sorting inside the Cube games -->
  38. <xsl:text>docident </xsl:text>
  39. <xsl:text>[</xsl:text>
  40. <xsl:value-of select="@name"/>
  41. <xsl:text>] [</xsl:text>
  42. <xsl:value-of select="normalize-space(t:description)"/>
  43. <xsl:text>];</xsl:text>
  44. <xsl:value-of select="$newline"/>
  45. <!-- argument descriptions -->
  46. <xsl:for-each select="t:arguments/*">
  47. <xsl:text>docargument </xsl:text>
  48. <xsl:text>[</xsl:text>
  49. <xsl:value-of select="@token"/>
  50. <xsl:text>] [</xsl:text>
  51. <xsl:value-of select="@description"/>
  52. <xsl:text>] [</xsl:text>
  53. <xsl:value-of select="@valueNotes"/>
  54. <xsl:text>] [</xsl:text>
  55. <xsl:choose>
  56. <xsl:when test="local-name() = 'variableArgument'">
  57. <xsl:text>1</xsl:text>
  58. </xsl:when>
  59. <xsl:otherwise>
  60. <xsl:text>0</xsl:text>
  61. </xsl:otherwise>
  62. </xsl:choose>
  63. <xsl:text>];</xsl:text>
  64. <xsl:value-of select="$newline"/>
  65. </xsl:for-each>
  66. <!-- var descriptions (fake arg) -->
  67. <xsl:if test="t:value">
  68. <xsl:text>docargument </xsl:text>
  69. <xsl:text>[</xsl:text>
  70. <xsl:value-of select="t:value/@token"/>
  71. <xsl:text>] [</xsl:text>
  72. <xsl:value-of select="t:value/@description"/>
  73. <xsl:text>] [</xsl:text>
  74. <xsl:value-of select="t:value/@valueNotes"/>
  75. <xsl:choose>
  76. <xsl:when test="t:value/@readOnly">
  77. <xsl:text> read-only</xsl:text>
  78. </xsl:when>
  79. <xsl:otherwise>
  80. <xsl:if test="t:value/@valueNotes">
  81. <xsl:text> </xsl:text>
  82. </xsl:if>
  83. <xsl:text>min </xsl:text>
  84. <xsl:value-of select="t:value/@minValue"/>
  85. <xsl:text>/max </xsl:text>
  86. <xsl:value-of select="t:value/@maxValue"/>
  87. <xsl:text>/default </xsl:text>
  88. <xsl:value-of select="t:value/@defaultValue"/>
  89. </xsl:otherwise>
  90. </xsl:choose>
  91. <xsl:text>];</xsl:text>
  92. <xsl:value-of select="$newline"/>
  93. </xsl:if>
  94. <!-- remarks -->
  95. <xsl:for-each select="t:remarks/t:remark">
  96. <xsl:text>docremark </xsl:text>
  97. <xsl:text>[</xsl:text>
  98. <xsl:value-of select="normalize-space(.)"/>
  99. <xsl:text>];</xsl:text>
  100. <xsl:value-of select="$newline"/>
  101. </xsl:for-each>
  102. <!-- examples -->
  103. <xsl:for-each select="t:examples/*">
  104. <xsl:text>docexample </xsl:text>
  105. <xsl:text>[</xsl:text>
  106. <xsl:value-of select="normalize-space(t:code)"/>
  107. <xsl:text>] [</xsl:text>
  108. <xsl:value-of select="normalize-space(t:explanation)"/><!-- FIXME: will only use the 1st explanation (2010oct06:flowtron) -->
  109. <xsl:text>];</xsl:text>
  110. <xsl:value-of select="$newline"/>
  111. </xsl:for-each>
  112. <!-- default keys -->
  113. <xsl:for-each select="t:defaultKeys/*">
  114. <xsl:text>dockey </xsl:text>
  115. <xsl:text>[</xsl:text>
  116. <xsl:value-of select="@alias"/>
  117. <xsl:text>] [</xsl:text>
  118. <xsl:value-of select="@name"/>
  119. <xsl:text>] [</xsl:text>
  120. <xsl:value-of select="@description"/>
  121. <xsl:text>];</xsl:text>
  122. <xsl:value-of select="$newline"/>
  123. </xsl:for-each>
  124. <!-- references -->
  125. <xsl:for-each select="t:references/t:identifierReference">
  126. <xsl:text>docref </xsl:text>
  127. <xsl:text>[</xsl:text>
  128. <xsl:value-of select="@identifier"/>
  129. <xsl:text>];</xsl:text>
  130. <xsl:value-of select="$newline"/>
  131. </xsl:for-each>
  132. </xsl:for-each>
  133. </xsl:for-each>
  134. </xsl:template>
  135. </xsl:stylesheet>