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="value-prop" select="property[@name='text']"/> 242 <xsl:attribute name="template:selector-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 243 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 244 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 245 </input> 246 </xsl:template> 247 248 <xsl:template match="widget[@class='QLineEdit']"> 249 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 250 <xsl:variable name="name-prop" select="property[@name='name']"/> 251 <xsl:variable name="value-prop" select="property[@name='text']"/> 252 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 253 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 254 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 255 </input> 256 </xsl:template> 257 258 <xsl:template match="widget[@class='QTextEdit']"> 259 <textarea xmlns="http://www.w3.org/1999/xhtml"> 260 <xsl:variable name="name-prop" select="property[@name='name']"/> 261 <xsl:variable name="value-prop" select="property[@name='text']"/> 262 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 263 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 264 <xsl:value-of select="$value-prop/string/text()"/> 265 </textarea> 266 </xsl:template> 267 268 <xsl:template match="widget[@class='QRadioButton']"> 269 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 270 <xsl:variable name="name-prop" select="property[@name='name']"/> 271 <xsl:variable name="value-prop" select="property[@name='text']"/> 272 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 273 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 274 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 275 </input> 276 </xsl:template> 277 278 279 280 <!-- Geometry. --> 281 282 <xsl:template match="property[@name='geometry']"> 283 <xsl:apply-templates select="rect/*[1]"> 284 <xsl:with-param name="style">position: absolute</xsl:with-param> 285 </xsl:apply-templates> 286 </xsl:template> 287 288 <xsl:template name="make-geometry"> 289 <xsl:param name="style"/> 290 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 291 <xsl:choose> 292 <xsl:when test="not($dimension)"> 293 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 294 </xsl:when> 295 <xsl:otherwise> 296 <xsl:apply-templates select="$dimension"> 297 <xsl:with-param name="style" select="$style"/> 298 </xsl:apply-templates> 299 </xsl:otherwise> 300 </xsl:choose> 301 </xsl:template> 302 303 <xsl:template match="x"> 304 <xsl:param name="style"/> 305 <xsl:call-template name="make-geometry"> 306 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 307 </xsl:call-template> 308 </xsl:template> 309 310 <xsl:template match="y"> 311 <xsl:param name="style"/> 312 <xsl:call-template name="make-geometry"> 313 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 314 </xsl:call-template> 315 </xsl:template> 316 317 <xsl:template match="width"> 318 <xsl:param name="style"/> 319 <xsl:call-template name="make-geometry"> 320 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 321 </xsl:call-template> 322 </xsl:template> 323 324 <xsl:template match="height"> 325 <xsl:param name="style"/> 326 <xsl:call-template name="make-geometry"> 327 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 328 </xsl:call-template> 329 </xsl:template> 330 331 332 333 <!-- Identification. --> 334 335 <xsl:template match="property[@name='name']"> 336 </xsl:template> 337 338 339 340 <!-- Labels and values. --> 341 342 <xsl:template match="property[@name='text']"> 343 </xsl:template> 344 345 346 347 <!-- Captions. --> 348 349 <xsl:template match="property[@name='caption']"> 350 </xsl:template> 351 352 353 354 <!-- Copy attributes. --> 355 356 <xsl:template match="@*"> 357 <xsl:copy> 358 <xsl:apply-templates select="node()"/> 359 </xsl:copy> 360 </xsl:template> 361 362 </xsl:stylesheet>