1 <?xml version="1.0"?> 2 <!-- 3 An experimental Qt Designer form conversion stylesheet. 4 5 Copyright (C) 2005 Paul Boddie <paul@boddie.org.uk> 6 7 This library is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 This library is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 You should have received a copy of the GNU Lesser General Public 18 License along with this library; if not, write to the Free Software 19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA 20 --> 21 <xsl:stylesheet version="1.0" 22 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 23 xmlns:set="http://exslt.org/sets" 24 xmlns:math="http://exslt.org/math" 25 xmlns:template="http://www.boddie.org.uk/ns/xmltools/template"> 26 27 <xsl:output indent="yes"/> 28 29 30 31 <!-- Start at the top, producing a template file. --> 32 33 <xsl:template match="UI"> 34 <html xmlns="http://www.w3.org/1999/xhtml"> 35 <head> 36 <title><xsl:value-of select="widget/property[@name='caption']/string/text()"/></title> 37 <link xmlns:xlink="http://www.w3.org/1999/xlink" href="styles/styles.css" rel="stylesheet" type="text/css" /> 38 <script type="text/javascript" src="scripts/sarissa.js"> </script> 39 <script type="text/javascript" src="scripts/XSLForms.js"> </script> 40 </head> 41 <body> 42 <form method="post"> 43 <xsl:apply-templates select="widget"/> 44 </form> 45 </body> 46 </html> 47 </xsl:template> 48 49 50 51 <!-- Reproduce the layout. --> 52 53 <xsl:template match="grid"> 54 <xsl:variable name="grid" select="."/> 55 <table xmlns="http://www.w3.org/1999/xhtml" width="100%"> 56 <!-- Get the row numbers in ascending order. --> 57 <xsl:for-each select="set:distinct($grid/*/@row)"> 58 <xsl:sort select="." data-type="number" order="ascending"/> 59 <xsl:variable name="row" select="."/> 60 <tr> 61 <!-- Get all elements in the row, ordered by column number. --> 62 <xsl:call-template name="grid-column"> 63 <xsl:with-param name="column" select="math:min($grid/*[@row=$row]/@column)"/> 64 <xsl:with-param name="row" select="$row"/> 65 <xsl:with-param name="grid" select="$grid"/> 66 <xsl:with-param name="last-column">-1</xsl:with-param> 67 </xsl:call-template> 68 </tr> 69 </xsl:for-each> 70 </table> 71 </xsl:template> 72 73 <xsl:template name="grid-column"> 74 <xsl:param name="column"/> 75 <xsl:param name="row"/> 76 <xsl:param name="grid"/> 77 <xsl:param name="last-column"/> 78 <xsl:param name="last-colspan">1</xsl:param> 79 <!-- Insert missing cells. --> 80 <xsl:if test="$column != $last-column + $last-colspan"> 81 <xsl:variable name="spanned-columns" select="$grid/*[$row > @row and @row + @rowspan > $row and @column > $last-column and $column > @column]/@column"/> 82 <xsl:choose> 83 <xsl:when test="count($spanned-columns) != 0"> 84 <xsl:variable name="last-spanned-column" select="math:highest($spanned-columns)"/> 85 <xsl:variable name="last-spanned-colspan" select="$last-spanned-column/../@colspan"/> 86 <xsl:if test="$column != $last-spanned-column + $last-spanned-colspan"> 87 <td colspan="{$column - $last-spanned-column - $last-spanned-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 88 </td> 89 </xsl:if> 90 </xsl:when> 91 <xsl:otherwise> 92 <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 93 </td> 94 </xsl:otherwise> 95 </xsl:choose> 96 </xsl:if> 97 <!-- Remember useful information. --> 98 <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/> 99 <xsl:variable name="this-colspan" select="$this-column/@colspan"/> 100 <!-- Insert this cell. --> 101 <td xmlns="http://www.w3.org/1999/xhtml"> 102 <!-- Add colspan and rowspan details. --> 103 <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/> 104 <!-- Transform the element. --> 105 <xsl:apply-templates select="$this-column"/> 106 </td> 107 <!-- Find remaining cells in this row. --> 108 <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0"> 109 <xsl:choose> 110 <xsl:when test="$this-colspan"> 111 <xsl:call-template name="grid-column"> 112 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 113 <xsl:with-param name="row" select="$row"/> 114 <xsl:with-param name="grid" select="$grid"/> 115 <xsl:with-param name="last-column" select="$column"/> 116 <xsl:with-param name="last-colspan" select="$this-colspan"/> 117 </xsl:call-template> 118 </xsl:when> 119 <xsl:otherwise> 120 <xsl:call-template name="grid-column"> 121 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 122 <xsl:with-param name="row" select="$row"/> 123 <xsl:with-param name="grid" select="$grid"/> 124 <xsl:with-param name="last-column" select="$column"/> 125 </xsl:call-template> 126 </xsl:otherwise> 127 </xsl:choose> 128 </xsl:if> 129 </xsl:template> 130 131 <xsl:template match="spacer"> 132 </xsl:template> 133 134 <xsl:template match="vbox"> 135 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 136 </xsl:template> 137 138 <xsl:template match="hbox"> 139 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 140 </xsl:template> 141 142 <xsl:template match="widget"> 143 <xsl:apply-templates select="property[@name='geometry']"/> 144 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 145 </xsl:template> 146 147 <!-- Container widgets. --> 148 149 <xsl:template match="widget[@class='QFrame']"> 150 <div xmlns="http://www.w3.org/1999/xhtml"> 151 <xsl:variable name="name-prop" select="property[@name='name']"/> 152 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 153 <xsl:apply-templates select="property[@name='geometry']"/> 154 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 155 </div> 156 </xsl:template> 157 158 <xsl:template match="widget[@class='QTabWidget']"> 159 <xsl:variable name="name-prop" select="property[@name='name']"/> 160 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 161 <xsl:apply-templates select="property[@name='geometry']"/> 162 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 163 </xsl:template> 164 165 <xsl:template match="widget[@class='QWidgetStack']"> 166 <xsl:variable name="name-prop" select="property[@name='name']"/> 167 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 168 <xsl:apply-templates select="property[@name='geometry']"/> 169 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 170 </xsl:template> 171 172 <xsl:template match="widget[@class='QWidget']"> 173 <!-- NOTE: Suppress overriding of names. --> 174 <xsl:if test="not(../@class) or ../@class != 'QTabWidget'"> 175 <xsl:variable name="name-prop" select="property[@name='name']"/> 176 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 177 </xsl:if> 178 <xsl:apply-templates select="property[@name='geometry']"/> 179 <xsl:apply-templates select="*[not(local-name() = 'property') and not(local-name() = 'attribute')]"/> 180 </xsl:template> 181 182 <!-- Specific widgets. --> 183 184 <xsl:template match="widget[@class='QComboBox']"> 185 <select xmlns="http://www.w3.org/1999/xhtml"> 186 <xsl:variable name="name-prop" select="property[@name='name']"/> 187 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 188 <!-- NOTE: Adding _enum suffix. --> 189 <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/> 190 <xsl:attribute name="template:multiple-choice-field"><xsl:value-of select="$field-name"/>,value</xsl:attribute> 191 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 192 <xsl:apply-templates select="item"> 193 <xsl:with-param name="enum-name" select="$enum-name"/> 194 </xsl:apply-templates> 195 </select> 196 </xsl:template> 197 198 <xsl:template match="widget[@class='QListBox']"> 199 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 200 <xsl:variable name="name-prop" select="property[@name='name']"/> 201 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 202 <!-- NOTE: Adding _enum suffix. --> 203 <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/> 204 <xsl:attribute name="template:multiple-choice-list-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$enum-name"/></xsl:attribute> 205 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 206 <xsl:apply-templates select="item"> 207 <xsl:with-param name="enum-name" select="$enum-name"/> 208 <xsl:with-param name="item-type">list</xsl:with-param> 209 </xsl:apply-templates> 210 </select> 211 </xsl:template> 212 213 <xsl:template match="item"> 214 <xsl:param name="enum-name"/> 215 <xsl:param name="item-type"/> 216 <option xmlns="http://www.w3.org/1999/xhtml"> 217 <xsl:choose> 218 <xsl:when test="$item-type = 'list'"> 219 <xsl:attribute name="template:multiple-choice-list-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute> 220 </xsl:when> 221 <xsl:otherwise> 222 <xsl:attribute name="template:multiple-choice-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute> 223 </xsl:otherwise> 224 </xsl:choose> 225 <xsl:variable name="value-prop" select="property[@name='text']"/> 226 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 227 <xsl:value-of select="$value-prop/string/text()"/> 228 </option> 229 </xsl:template> 230 231 <xsl:template match="widget[@class='QLabel']"> 232 <xsl:variable name="value-prop" select="property[@name='text']"/> 233 <!-- NOTE: Permitting element generation from the text. --> 234 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 235 </xsl:template> 236 237 <xsl:template match="widget[@class='QPushButton']"> 238 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 239 <xsl:variable name="name-prop" select="property[@name='name']"/> 240 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 241 <xsl:variable name="value-prop" select="property[@name='text']"/> 242 <xsl:choose> 243 <xsl:when test="starts-with($field-name, 'add_')"> 244 <xsl:variable name="affected-element" select="substring-after($field-name, 'add_')"/> 245 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute> 246 </xsl:when> 247 <xsl:when test="starts-with($field-name, 'remove_')"> 248 <xsl:variable name="affected-element" select="substring-after($field-name, 'remove_')"/> 249 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute> 250 </xsl:when> 251 <xsl:otherwise> 252 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/></xsl:attribute> 253 </xsl:otherwise> 254 </xsl:choose> 255 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 256 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 257 </input> 258 </xsl:template> 259 260 <xsl:template match="widget[@class='QLineEdit']"> 261 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 262 <xsl:variable name="name-prop" select="property[@name='name']"/> 263 <xsl:variable name="value-prop" select="property[@name='text']"/> 264 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 265 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 266 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 267 </input> 268 </xsl:template> 269 270 <xsl:template match="widget[@class='QTextEdit']"> 271 <textarea xmlns="http://www.w3.org/1999/xhtml"> 272 <xsl:variable name="name-prop" select="property[@name='name']"/> 273 <xsl:variable name="value-prop" select="property[@name='text']"/> 274 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 275 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 276 <xsl:value-of select="$value-prop/string/text()"/> 277 </textarea> 278 </xsl:template> 279 280 <xsl:template match="widget[@class='QRadioButton']"> 281 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 282 <xsl:variable name="name-prop" select="property[@name='name']"/> 283 <xsl:variable name="value-prop" select="property[@name='text']"/> 284 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 285 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 286 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 287 </input> 288 </xsl:template> 289 290 291 292 <!-- Geometry. --> 293 294 <xsl:template match="property[@name='geometry']"> 295 <xsl:apply-templates select="rect/*[1]"> 296 <xsl:with-param name="style">position: absolute</xsl:with-param> 297 </xsl:apply-templates> 298 </xsl:template> 299 300 <xsl:template name="make-geometry"> 301 <xsl:param name="style"/> 302 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 303 <xsl:choose> 304 <xsl:when test="not($dimension)"> 305 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 306 </xsl:when> 307 <xsl:otherwise> 308 <xsl:apply-templates select="$dimension"> 309 <xsl:with-param name="style" select="$style"/> 310 </xsl:apply-templates> 311 </xsl:otherwise> 312 </xsl:choose> 313 </xsl:template> 314 315 <xsl:template match="x"> 316 <xsl:param name="style"/> 317 <xsl:call-template name="make-geometry"> 318 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 319 </xsl:call-template> 320 </xsl:template> 321 322 <xsl:template match="y"> 323 <xsl:param name="style"/> 324 <xsl:call-template name="make-geometry"> 325 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 326 </xsl:call-template> 327 </xsl:template> 328 329 <xsl:template match="width"> 330 <xsl:param name="style"/> 331 <xsl:call-template name="make-geometry"> 332 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 333 </xsl:call-template> 334 </xsl:template> 335 336 <xsl:template match="height"> 337 <xsl:param name="style"/> 338 <xsl:call-template name="make-geometry"> 339 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 340 </xsl:call-template> 341 </xsl:template> 342 343 344 345 <!-- Identification. --> 346 347 <xsl:template match="property[@name='name']"> 348 </xsl:template> 349 350 351 352 <!-- Labels and values. --> 353 354 <xsl:template match="property[@name='text']"> 355 </xsl:template> 356 357 358 359 <!-- Captions. --> 360 361 <xsl:template match="property[@name='caption']"> 362 </xsl:template> 363 364 365 366 <!-- Copy attributes. --> 367 368 <xsl:template match="@*"> 369 <xsl:copy> 370 <xsl:apply-templates select="node()"/> 371 </xsl:copy> 372 </xsl:template> 373 374 </xsl:stylesheet>