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