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 <xsl:apply-templates select="widget"/> 43 </body> 44 </html> 45 </xsl:template> 46 47 48 49 <!-- Reproduce the layout. --> 50 51 <xsl:template match="grid"> 52 <xsl:variable name="grid" select="."/> 53 <table xmlns="http://www.w3.org/1999/xhtml"> 54 <!-- Get the row numbers in ascending order. --> 55 <xsl:for-each select="set:distinct($grid/*/@row)"> 56 <xsl:sort select="." data-type="number" order="ascending"/> 57 <xsl:variable name="row" select="."/> 58 <tr> 59 <!-- Get all elements in the row, ordered by column number. --> 60 <xsl:call-template name="grid-column"> 61 <xsl:with-param name="column" select="math:min($grid/*[@row=$row]/@column)"/> 62 <xsl:with-param name="row" select="$row"/> 63 <xsl:with-param name="grid" select="$grid"/> 64 <xsl:with-param name="last-column">-1</xsl:with-param> 65 </xsl:call-template> 66 </tr> 67 </xsl:for-each> 68 </table> 69 </xsl:template> 70 71 <xsl:template name="grid-column"> 72 <xsl:param name="column"/> 73 <xsl:param name="row"/> 74 <xsl:param name="grid"/> 75 <xsl:param name="last-column"/> 76 <xsl:param name="last-colspan">1</xsl:param> 77 <!-- Insert missing cells. --> 78 <!-- NOTE: This does not handle rowspan usage. --> 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> 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:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 187 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 188 <xsl:apply-templates select="item"/> 189 </select> 190 </xsl:template> 191 192 <xsl:template match="widget[@class='QListBox']"> 193 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 194 <xsl:variable name="name-prop" select="property[@name='name']"/> 195 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 196 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 197 <xsl:apply-templates select="item"/> 198 </select> 199 </xsl:template> 200 201 <xsl:template match="item"> 202 <option xmlns="http://www.w3.org/1999/xhtml"> 203 <xsl:variable name="value-prop" select="property[@name='text']"/> 204 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 205 <xsl:value-of select="$value-prop/string/text()"/> 206 </option> 207 </xsl:template> 208 209 <xsl:template match="widget[@class='QLabel']"> 210 <xsl:variable name="value-prop" select="property[@name='text']"/> 211 <!-- NOTE: Permitting element generation from the text. --> 212 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 213 </xsl:template> 214 215 <xsl:template match="widget[@class='QPushButton']"> 216 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 217 <xsl:variable name="name-prop" select="property[@name='name']"/> 218 <xsl:variable name="value-prop" select="property[@name='text']"/> 219 <xsl:attribute name="template:selector-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 220 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 221 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 222 </input> 223 </xsl:template> 224 225 <xsl:template match="widget[@class='QLineEdit']"> 226 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 227 <xsl:variable name="name-prop" select="property[@name='name']"/> 228 <xsl:variable name="value-prop" select="property[@name='text']"/> 229 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 230 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 231 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 232 </input> 233 </xsl:template> 234 235 <xsl:template match="widget[@class='QTextEdit']"> 236 <textarea xmlns="http://www.w3.org/1999/xhtml"> 237 <xsl:variable name="name-prop" select="property[@name='name']"/> 238 <xsl:variable name="value-prop" select="property[@name='text']"/> 239 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 240 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 241 <xsl:value-of select="$value-prop/string/text()"/> 242 </textarea> 243 </xsl:template> 244 245 <xsl:template match="widget[@class='QRadioButton']"> 246 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 247 <xsl:variable name="name-prop" select="property[@name='name']"/> 248 <xsl:variable name="value-prop" select="property[@name='text']"/> 249 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 250 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 251 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 252 </input> 253 </xsl:template> 254 255 256 257 <!-- Geometry. --> 258 259 <xsl:template match="property[@name='geometry']"> 260 <xsl:apply-templates select="rect/*[1]"> 261 <xsl:with-param name="style">position: absolute</xsl:with-param> 262 </xsl:apply-templates> 263 </xsl:template> 264 265 <xsl:template name="make-geometry"> 266 <xsl:param name="style"/> 267 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 268 <xsl:choose> 269 <xsl:when test="not($dimension)"> 270 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 271 </xsl:when> 272 <xsl:otherwise> 273 <xsl:apply-templates select="$dimension"> 274 <xsl:with-param name="style" select="$style"/> 275 </xsl:apply-templates> 276 </xsl:otherwise> 277 </xsl:choose> 278 </xsl:template> 279 280 <xsl:template match="x"> 281 <xsl:param name="style"/> 282 <xsl:call-template name="make-geometry"> 283 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 284 </xsl:call-template> 285 </xsl:template> 286 287 <xsl:template match="y"> 288 <xsl:param name="style"/> 289 <xsl:call-template name="make-geometry"> 290 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 291 </xsl:call-template> 292 </xsl:template> 293 294 <xsl:template match="width"> 295 <xsl:param name="style"/> 296 <xsl:call-template name="make-geometry"> 297 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 298 </xsl:call-template> 299 </xsl:template> 300 301 <xsl:template match="height"> 302 <xsl:param name="style"/> 303 <xsl:call-template name="make-geometry"> 304 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 305 </xsl:call-template> 306 </xsl:template> 307 308 309 310 <!-- Identification. --> 311 312 <xsl:template match="property[@name='name']"> 313 </xsl:template> 314 315 316 317 <!-- Labels and values. --> 318 319 <xsl:template match="property[@name='text']"> 320 </xsl:template> 321 322 323 324 <!-- Captions. --> 325 326 <xsl:template match="property[@name='caption']"> 327 </xsl:template> 328 329 330 331 <!-- Copy attributes. --> 332 333 <xsl:template match="@*"> 334 <xsl:copy> 335 <xsl:apply-templates select="node()"/> 336 </xsl:copy> 337 </xsl:template> 338 339 </xsl:stylesheet>