ctkCmdLineModuleXmlToPlainHtml.xsl 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet version="2.0"
  3. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  4. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  5. xmlns:fn="http://www.w3.org/2005/xpath-functions"
  6. xmlns:xdt="http://www.w3.org/2005/xpath-datatypes"
  7. xmlns:err="http://www.w3.org/2005/xqt-errors"
  8. xmlns:ctk="http://www.commontk.org"
  9. exclude-result-prefixes="xs xdt err fn">
  10. <xsl:output method="xhtml" indent="yes"/>
  11. <!--
  12. ===================================================================
  13. Utility XSLT 2.0 functions
  14. ===================================================================
  15. -->
  16. <!-- Map xml parameter element names (types) to a class attribute. -->
  17. <xsl:function name="ctk:mapTypeToXmlClass">
  18. <xsl:param name="cliType"/>
  19. <xsl:choose>
  20. <xsl:when test="$cliType='boolean'">bool</xsl:when>
  21. <xsl:when test="$cliType='integer'">number</xsl:when>
  22. <xsl:when test="$cliType='float'">double</xsl:when>
  23. <xsl:when test="$cliType=('point', 'region', 'image', 'file', 'directory', 'geometry', 'integer-vector', 'double-vector', 'float-vector', 'string-vector', 'integer-enumeration', 'double-enumeration', 'float-enumeration', 'string-enumeration')">string</xsl:when>
  24. <xsl:otherwise><xsl:value-of select="$cliType"/></xsl:otherwise>
  25. </xsl:choose>
  26. </xsl:function>
  27. <!-- Map xml parameter element names (types) to the Qt widget property containing
  28. the current value. The property value type should match the (Qt) C++ type
  29. (or be convertible to it). -->
  30. <xsl:function name="ctk:mapTypeToQtValueProperty">
  31. <xsl:param name="cliType"/>
  32. <xsl:choose>
  33. <xsl:when test="$cliType='boolean'">checked</xsl:when>
  34. <xsl:when test="$cliType= ('point', 'region')">coordinates</xsl:when>
  35. <xsl:when test="$cliType= ('image', 'file', 'directory', 'geometry')">currentPath</xsl:when>
  36. <xsl:when test="$cliType= ('string', 'integer-vector', 'float-vector', 'double-vector', 'string-vector')">text</xsl:when>
  37. <xsl:when test="$cliType= ('integer-enumeration', 'float-enumeration', 'double-enumeration', 'string-enumeration')">currentText</xsl:when>
  38. <xsl:otherwise>value</xsl:otherwise>
  39. </xsl:choose>
  40. </xsl:function>
  41. <!--
  42. ===================================================================
  43. Default templates for suppressing output if no more specific template exists
  44. ===================================================================
  45. -->
  46. <!-- suppress text and attribute nodes not covered in subsequent template rule -->
  47. <xsl:template match="text()|@*"/>
  48. <!--
  49. ===================================================================
  50. Utility templates
  51. ===================================================================
  52. -->
  53. <xsl:template match="parameters/label">
  54. <p><xsl:value-of select="text()"/></p>
  55. </xsl:template>
  56. <!-- Add a tooltip property to a widget -->
  57. <xsl:template match="description">
  58. <property name="toolTip">
  59. <string><xsl:value-of select="text()"/></string>
  60. </property>
  61. </xsl:template>
  62. <!-- Set the default value by generating a Qt widget specific property which holds
  63. the current value -->
  64. <xsl:template match="default">
  65. <property name="{ctk:mapTypeToQtValueProperty(name(..))}">
  66. <xsl:element name="{ctk:mapTypeToXmlClass(name(..))}"><xsl:value-of select="text()"/></xsl:element>
  67. </property>
  68. </xsl:template>
  69. <!-- Set Qt widget (spinbox) specific properties for applying constraints of scalar parameters -->
  70. <xsl:template match="constraints/*[name()=('minimum','maximum')]">
  71. <property name="{name()}">
  72. <xsl:element name="{ctk:mapTypeToXmlClass(name(../..))}"><xsl:value-of select="text()"/></xsl:element>
  73. </property>
  74. </xsl:template>
  75. <xsl:template match="constraints/step">
  76. <property name="singleStep">
  77. <xsl:element name="{ctk:mapTypeToXmlClass(name(../..))}"><xsl:value-of select="text()"/></xsl:element>
  78. </property>
  79. <!-- Also add the 'step' information under the original name -->
  80. <property name="parameter:step">
  81. <string><xsl:value-of select="text()"/></string>
  82. </property>
  83. </xsl:template>
  84. <!-- A named template which will be called from each parameter (integer, float, image, etc.) element.
  85. It assumes that it will be called from an enclosing Qt grid layout element and adds a label item -->
  86. <xsl:template name="gridItemWithLabel">
  87. <td><xsl:value-of select="./label"/></td>
  88. </xsl:template>
  89. <!-- A named template for adding properties common to all Qt widgets -->
  90. <xsl:template name="commonWidgetProperties">
  91. <xsl:apply-templates select="description"/> <!-- tooltip -->
  92. <xsl:if test="@hidden='true'"> <!-- widget visibility -->
  93. <property name="visible">
  94. <bool>false</bool>
  95. </property>
  96. </xsl:if>
  97. <property name="parameter:valueProperty"> <!-- property name containing current value -->
  98. <string><xsl:value-of select="ctk:mapTypeToQtValueProperty(name())"/></string>
  99. </property>
  100. <!-- add additional (optional) information as properties -->
  101. <xsl:apply-templates select="default"/>
  102. </xsl:template>
  103. <!--
  104. ===================================================================
  105. Match elements from the XML description
  106. ===================================================================
  107. -->
  108. <!-- start matching at 'executable' element -->
  109. <xsl:template match="/executable">
  110. <xsl:variable name="moduleTitle"><xsl:value-of select="title"/></xsl:variable>
  111. <html>
  112. <head>
  113. <title><xsl:value-of select="title"/></title>
  114. </head>
  115. <body>
  116. <form>
  117. <div class="executable">
  118. <!-- This will generate DIV elements with the specific widgets -->
  119. <xsl:apply-templates select="parameters"/>
  120. </div>
  121. </form>
  122. </body>
  123. </html>
  124. </xsl:template>
  125. <!--
  126. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  127. Parameters
  128. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  129. -->
  130. <!-- Match the 'parameters' element and create the parameter groups (QGroupBox) -->
  131. <xsl:template match="parameters">
  132. <xsl:variable name="groupLabel"><xsl:value-of select="label"/></xsl:variable>
  133. <div class="parameters">
  134. <xsl:apply-templates select="./label"/>
  135. <xsl:apply-templates select="./description"/>
  136. <table>
  137. <xsl:apply-templates select="./description/following-sibling::*"/>
  138. </table>
  139. </div>
  140. </xsl:template>
  141. <!--
  142. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  143. BOOLEAN parameter (default: QCheckbox)
  144. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145. -->
  146. <xsl:template match="parameters/boolean">
  147. <tr>
  148. <xsl:call-template name="gridItemWithLabel"/>
  149. <td><input type="checkbox" name="{name}"/></td>
  150. </tr>
  151. </xsl:template>
  152. <!--
  153. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  154. IMAGE, FILE, GEOMETRY parameter (default: ctkPathLineEdit)
  155. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  156. -->
  157. <xsl:template match="parameters/*[name()=('image', 'file', 'geometry')]">
  158. <tr>
  159. <xsl:call-template name="gridItemWithLabel"/>
  160. <td><input type="file" name="{name}"/></td>
  161. </tr>
  162. </xsl:template>
  163. <!--
  164. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165. DEFAULT
  166. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167. -->
  168. <xsl:template match="parameters/*" priority="-1">
  169. <tr>
  170. <xsl:call-template name="gridItemWithLabel"/>
  171. <td>
  172. <input type="text" name="{name}">
  173. <xsl:attribute name="value">
  174. <xsl:value-of select="default/text()"/>
  175. </xsl:attribute>
  176. </input>
  177. </td>
  178. </tr>
  179. </xsl:template>
  180. </xsl:stylesheet>