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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"> 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 <!-- NOTE: This does not handle rowspan usage. --> 81 <xsl:if test="$column != $last-column + $last-colspan"> 82 <xsl:variable name="spanned-columns" select="$grid/*[$row > @row and @row + @rowspan > $row and @column > $last-column and $column > @column]/@column"/> 83 <xsl:choose> 84 <xsl:when test="count($spanned-columns) != 0"> 85 <xsl:variable name="last-spanned-column" select="math:highest($spanned-columns)"/> 86 <xsl:variable name="last-spanned-colspan" select="$last-spanned-column/../@colspan"/> 87 <xsl:if test="$column != $last-spanned-column + $last-spanned-colspan"> 88 <td colspan="{$column - $last-spanned-column - $last-spanned-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 89 </td> 90 </xsl:if> 91 </xsl:when> 92 <xsl:otherwise> 93 <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 94 </td> 95 </xsl:otherwise> 96 </xsl:choose> 97 </xsl:if> 98 <!-- Remember useful information. --> 99 <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/> 100 <xsl:variable name="this-colspan" select="$this-column/@colspan"/> 101 <!-- Insert this cell. --> 102 <td xmlns="http://www.w3.org/1999/xhtml"> 103 <!-- Add colspan and rowspan details. --> 104 <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/> 105 <!-- Transform the element. --> 106 <xsl:apply-templates select="$this-column"/> 107 </td> 108 <!-- Find remaining cells in this row. --> 109 <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0"> 110 <xsl:choose> 111 <xsl:when test="$this-colspan"> 112 <xsl:call-template name="grid-column"> 113 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 114 <xsl:with-param name="row" select="$row"/> 115 <xsl:with-param name="grid" select="$grid"/> 116 <xsl:with-param name="last-column" select="$column"/> 117 <xsl:with-param name="last-colspan" select="$this-colspan"/> 118 </xsl:call-template> 119 </xsl:when> 120 <xsl:otherwise> 121 <xsl:call-template name="grid-column"> 122 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 123 <xsl:with-param name="row" select="$row"/> 124 <xsl:with-param name="grid" select="$grid"/> 125 <xsl:with-param name="last-column" select="$column"/> 126 </xsl:call-template> 127 </xsl:otherwise> 128 </xsl:choose> 129 </xsl:if> 130 </xsl:template> 131 132 <xsl:template match="spacer"> 133 </xsl:template> 134 135 <xsl:template match="vbox"> 136 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 137 </xsl:template> 138 139 <xsl:template match="hbox"> 140 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 141 </xsl:template> 142 143 <xsl:template match="widget"> 144 <xsl:apply-templates select="property[@name='geometry']"/> 145 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 146 </xsl:template> 147 148 <!-- Container widgets. --> 149 150 <xsl:template match="widget[@class='QFrame']"> 151 <div> 152 <xsl:variable name="name-prop" select="property[@name='name']"/> 153 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 154 <xsl:apply-templates select="property[@name='geometry']"/> 155 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 156 </div> 157 </xsl:template> 158 159 <xsl:template match="widget[@class='QTabWidget']"> 160 <xsl:variable name="name-prop" select="property[@name='name']"/> 161 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 162 <xsl:apply-templates select="property[@name='geometry']"/> 163 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 164 </xsl:template> 165 166 <xsl:template match="widget[@class='QWidgetStack']"> 167 <xsl:variable name="name-prop" select="property[@name='name']"/> 168 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 169 <xsl:apply-templates select="property[@name='geometry']"/> 170 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 171 </xsl:template> 172 173 <xsl:template match="widget[@class='QWidget']"> 174 <!-- NOTE: Suppress overriding of names. --> 175 <xsl:if test="not(../@class) or ../@class != 'QTabWidget'"> 176 <xsl:variable name="name-prop" select="property[@name='name']"/> 177 <xsl:attribute name="template:element"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 178 </xsl:if> 179 <xsl:apply-templates select="property[@name='geometry']"/> 180 <xsl:apply-templates select="*[not(local-name() = 'property') and not(local-name() = 'attribute')]"/> 181 </xsl:template> 182 183 <!-- Specific widgets. --> 184 185 <xsl:template match="widget[@class='QComboBox']"> 186 <select xmlns="http://www.w3.org/1999/xhtml"> 187 <xsl:variable name="name-prop" select="property[@name='name']"/> 188 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 189 <!-- NOTE: Adding _enum suffix. --> 190 <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/> 191 <xsl:attribute name="template:multiple-choice-field"><xsl:value-of select="$field-name"/>,value</xsl:attribute> 192 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 193 <xsl:apply-templates select="item"> 194 <xsl:with-param name="enum-name" select="$enum-name"/> 195 </xsl:apply-templates> 196 </select> 197 </xsl:template> 198 199 <xsl:template match="widget[@class='QListBox']"> 200 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 201 <xsl:variable name="name-prop" select="property[@name='name']"/> 202 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 203 <!-- NOTE: Adding _enum suffix. --> 204 <xsl:variable name="enum-name" select="concat($name-prop/cstring/text(), '_enum')"/> 205 <xsl:attribute name="template:multiple-choice-list-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$enum-name"/></xsl:attribute> 206 <xsl:attribute name="name"><xsl:value-of select="$field-name"/></xsl:attribute> 207 <xsl:apply-templates select="item"> 208 <xsl:with-param name="enum-name" select="$enum-name"/> 209 <xsl:with-param name="item-type">list</xsl:with-param> 210 </xsl:apply-templates> 211 </select> 212 </xsl:template> 213 214 <xsl:template match="item"> 215 <xsl:param name="enum-name"/> 216 <xsl:param name="item-type"/> 217 <option xmlns="http://www.w3.org/1999/xhtml"> 218 <xsl:choose> 219 <xsl:when test="$item-type = 'list'"> 220 <xsl:attribute name="template:multiple-choice-list-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute> 221 </xsl:when> 222 <xsl:otherwise> 223 <xsl:attribute name="template:multiple-choice-value"><xsl:value-of select="$enum-name"/>,value,selected</xsl:attribute> 224 </xsl:otherwise> 225 </xsl:choose> 226 <xsl:variable name="value-prop" select="property[@name='text']"/> 227 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 228 <xsl:value-of select="$value-prop/string/text()"/> 229 </option> 230 </xsl:template> 231 232 <xsl:template match="widget[@class='QLabel']"> 233 <xsl:variable name="value-prop" select="property[@name='text']"/> 234 <!-- NOTE: Permitting element generation from the text. --> 235 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 236 </xsl:template> 237 238 <xsl:template match="widget[@class='QPushButton']"> 239 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 240 <xsl:variable name="name-prop" select="property[@name='name']"/> 241 <xsl:variable name="field-name" select="$name-prop/cstring/text()"/> 242 <xsl:variable name="value-prop" select="property[@name='text']"/> 243 <xsl:choose> 244 <xsl:when test="starts-with($field-name, 'add_')"> 245 <xsl:variable name="affected-element" select="substring-after($field-name, 'add_')"/> 246 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute> 247 </xsl:when> 248 <xsl:when test="starts-with($field-name, 'remove_')"> 249 <xsl:variable name="affected-element" select="substring-after($field-name, 'remove_')"/> 250 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/>,<xsl:value-of select="$affected-element"/></xsl:attribute> 251 </xsl:when> 252 <xsl:otherwise> 253 <xsl:attribute name="template:selector-field"><xsl:value-of select="$field-name"/></xsl:attribute> 254 </xsl:otherwise> 255 </xsl:choose> 256 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 257 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 258 </input> 259 </xsl:template> 260 261 <xsl:template match="widget[@class='QLineEdit']"> 262 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 263 <xsl:variable name="name-prop" select="property[@name='name']"/> 264 <xsl:variable name="value-prop" select="property[@name='text']"/> 265 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 266 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 267 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 268 </input> 269 </xsl:template> 270 271 <xsl:template match="widget[@class='QTextEdit']"> 272 <textarea xmlns="http://www.w3.org/1999/xhtml"> 273 <xsl:variable name="name-prop" select="property[@name='name']"/> 274 <xsl:variable name="value-prop" select="property[@name='text']"/> 275 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 276 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 277 <xsl:value-of select="$value-prop/string/text()"/> 278 </textarea> 279 </xsl:template> 280 281 <xsl:template match="widget[@class='QRadioButton']"> 282 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 283 <xsl:variable name="name-prop" select="property[@name='name']"/> 284 <xsl:variable name="value-prop" select="property[@name='text']"/> 285 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 286 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 287 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 288 </input> 289 </xsl:template> 290 291 292 293 <!-- Geometry. --> 294 295 <xsl:template match="property[@name='geometry']"> 296 <xsl:apply-templates select="rect/*[1]"> 297 <xsl:with-param name="style">position: absolute</xsl:with-param> 298 </xsl:apply-templates> 299 </xsl:template> 300 301 <xsl:template name="make-geometry"> 302 <xsl:param name="style"/> 303 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 304 <xsl:choose> 305 <xsl:when test="not($dimension)"> 306 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 307 </xsl:when> 308 <xsl:otherwise> 309 <xsl:apply-templates select="$dimension"> 310 <xsl:with-param name="style" select="$style"/> 311 </xsl:apply-templates> 312 </xsl:otherwise> 313 </xsl:choose> 314 </xsl:template> 315 316 <xsl:template match="x"> 317 <xsl:param name="style"/> 318 <xsl:call-template name="make-geometry"> 319 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 320 </xsl:call-template> 321 </xsl:template> 322 323 <xsl:template match="y"> 324 <xsl:param name="style"/> 325 <xsl:call-template name="make-geometry"> 326 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 327 </xsl:call-template> 328 </xsl:template> 329 330 <xsl:template match="width"> 331 <xsl:param name="style"/> 332 <xsl:call-template name="make-geometry"> 333 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 334 </xsl:call-template> 335 </xsl:template> 336 337 <xsl:template match="height"> 338 <xsl:param name="style"/> 339 <xsl:call-template name="make-geometry"> 340 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 341 </xsl:call-template> 342 </xsl:template> 343 344 345 346 <!-- Identification. --> 347 348 <xsl:template match="property[@name='name']"> 349 </xsl:template> 350 351 352 353 <!-- Labels and values. --> 354 355 <xsl:template match="property[@name='text']"> 356 </xsl:template> 357 358 359 360 <!-- Captions. --> 361 362 <xsl:template match="property[@name='caption']"> 363 </xsl:template> 364 365 366 367 <!-- Copy attributes. --> 368 369 <xsl:template match="@*"> 370 <xsl:copy> 371 <xsl:apply-templates select="node()"/> 372 </xsl:copy> 373 </xsl:template> 374 375 </xsl:stylesheet>