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 <td colspan="{$column - $last-column - $last-colspan}" xmlns="http://www.w3.org/1999/xhtml"> 81 </td> 82 </xsl:if> 83 <!-- Remember useful information. --> 84 <xsl:variable name="this-column" select="$grid/*[@row=$row and @column=$column]"/> 85 <xsl:variable name="this-colspan" select="$this-column/@colspan"/> 86 <!-- Insert this cell. --> 87 <td xmlns="http://www.w3.org/1999/xhtml"> 88 <!-- Add colspan and rowspan details. --> 89 <xsl:apply-templates select="$this-colspan|$this-column/@rowspan"/> 90 <!-- Transform the element. --> 91 <xsl:apply-templates select="$this-column"/> 92 </td> 93 <!-- Find remaining cells in this row. --> 94 <xsl:if test="count($grid/*[@row=$row and @column > $column]) > 0"> 95 <xsl:choose> 96 <xsl:when test="$this-colspan"> 97 <xsl:call-template name="grid-column"> 98 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 99 <xsl:with-param name="row" select="$row"/> 100 <xsl:with-param name="grid" select="$grid"/> 101 <xsl:with-param name="last-column" select="$column"/> 102 <xsl:with-param name="last-colspan" select="$this-colspan"/> 103 </xsl:call-template> 104 </xsl:when> 105 <xsl:otherwise> 106 <xsl:call-template name="grid-column"> 107 <xsl:with-param name="column" select="math:min($grid/*[@row=$row and @column > $column]/@column)"/> 108 <xsl:with-param name="row" select="$row"/> 109 <xsl:with-param name="grid" select="$grid"/> 110 <xsl:with-param name="last-column" select="$column"/> 111 </xsl:call-template> 112 </xsl:otherwise> 113 </xsl:choose> 114 </xsl:if> 115 </xsl:template> 116 117 <xsl:template match="spacer"> 118 </xsl:template> 119 120 <xsl:template match="vbox"> 121 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 122 </xsl:template> 123 124 <xsl:template match="widget"> 125 <xsl:apply-templates select="property[@name='geometry']"/> 126 <xsl:apply-templates select="*[not(local-name() = 'property')]"/> 127 </xsl:template> 128 129 130 131 <!-- Specific widgets. --> 132 133 <xsl:template match="widget[@class='QComboBox']"> 134 <select xmlns="http://www.w3.org/1999/xhtml"> 135 <xsl:variable name="name-prop" select="property[@name='name']"/> 136 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 137 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 138 <xsl:apply-templates select="item"/> 139 </select> 140 </xsl:template> 141 142 <xsl:template match="widget[@class='QListBox']"> 143 <select xmlns="http://www.w3.org/1999/xhtml" multiple="multiple"> 144 <xsl:variable name="name-prop" select="property[@name='name']"/> 145 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 146 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 147 <xsl:apply-templates select="item"/> 148 </select> 149 </xsl:template> 150 151 <xsl:template match="item"> 152 <option xmlns="http://www.w3.org/1999/xhtml"> 153 <xsl:variable name="value-prop" select="property[@name='text']"/> 154 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 155 <xsl:value-of select="$value-prop/string/text()"/> 156 </option> 157 </xsl:template> 158 159 <xsl:template match="widget[@class='QLabel']"> 160 <xsl:variable name="value-prop" select="property[@name='text']"/> 161 <!-- NOTE: Permitting element generation from the text. --> 162 <xsl:value-of disable-output-escaping="yes" select="$value-prop/string/text()"/> 163 </xsl:template> 164 165 <xsl:template match="widget[@class='QPushButton']"> 166 <input xmlns="http://www.w3.org/1999/xhtml" type="submit"> 167 <xsl:variable name="name-prop" select="property[@name='name']"/> 168 <xsl:variable name="value-prop" select="property[@name='text']"/> 169 <xsl:attribute name="template:attribute-button"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 170 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 171 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 172 </input> 173 </xsl:template> 174 175 <xsl:template match="widget[@class='QLineEdit']"> 176 <input xmlns="http://www.w3.org/1999/xhtml" type="text"> 177 <xsl:variable name="name-prop" select="property[@name='name']"/> 178 <xsl:variable name="value-prop" select="property[@name='text']"/> 179 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 180 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 181 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 182 </input> 183 </xsl:template> 184 185 <xsl:template match="widget[@class='QTextEdit']"> 186 <textarea xmlns="http://www.w3.org/1999/xhtml"> 187 <xsl:variable name="name-prop" select="property[@name='name']"/> 188 <xsl:variable name="value-prop" select="property[@name='text']"/> 189 <xsl:attribute name="template:attribute-area"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 190 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 191 <xsl:value-of select="$value-prop/string/text()"/> 192 </textarea> 193 </xsl:template> 194 195 <xsl:template match="widget[@class='QRadioButton']"> 196 <input xmlns="http://www.w3.org/1999/xhtml" type="radio"> 197 <xsl:variable name="name-prop" select="property[@name='name']"/> 198 <xsl:variable name="value-prop" select="property[@name='text']"/> 199 <xsl:attribute name="template:attribute-field"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 200 <xsl:attribute name="name"><xsl:value-of select="$name-prop/cstring/text()"/></xsl:attribute> 201 <xsl:attribute name="value"><xsl:value-of select="$value-prop/string/text()"/></xsl:attribute> 202 </input> 203 </xsl:template> 204 205 206 207 <!-- Geometry. --> 208 209 <xsl:template match="property[@name='geometry']"> 210 <xsl:apply-templates select="rect/*[1]"> 211 <xsl:with-param name="style">position: absolute</xsl:with-param> 212 </xsl:apply-templates> 213 </xsl:template> 214 215 <xsl:template name="make-geometry"> 216 <xsl:param name="style"/> 217 <xsl:variable name="dimension" select="following-sibling::*[1]"/> 218 <xsl:choose> 219 <xsl:when test="not($dimension)"> 220 <xsl:attribute name="style"><xsl:value-of select="$style"/></xsl:attribute> 221 </xsl:when> 222 <xsl:otherwise> 223 <xsl:apply-templates select="$dimension"> 224 <xsl:with-param name="style" select="$style"/> 225 </xsl:apply-templates> 226 </xsl:otherwise> 227 </xsl:choose> 228 </xsl:template> 229 230 <xsl:template match="x"> 231 <xsl:param name="style"/> 232 <xsl:call-template name="make-geometry"> 233 <xsl:with-param name="style"><xsl:value-of select="$style"/>; left: <xsl:value-of select="text()"/>px</xsl:with-param> 234 </xsl:call-template> 235 </xsl:template> 236 237 <xsl:template match="y"> 238 <xsl:param name="style"/> 239 <xsl:call-template name="make-geometry"> 240 <xsl:with-param name="style"><xsl:value-of select="$style"/>; top: <xsl:value-of select="text()"/>px</xsl:with-param> 241 </xsl:call-template> 242 </xsl:template> 243 244 <xsl:template match="width"> 245 <xsl:param name="style"/> 246 <xsl:call-template name="make-geometry"> 247 <xsl:with-param name="style"><xsl:value-of select="$style"/>; width: <xsl:value-of select="text()"/>px</xsl:with-param> 248 </xsl:call-template> 249 </xsl:template> 250 251 <xsl:template match="height"> 252 <xsl:param name="style"/> 253 <xsl:call-template name="make-geometry"> 254 <xsl:with-param name="style"><xsl:value-of select="$style"/>; height: <xsl:value-of select="text()"/>px</xsl:with-param> 255 </xsl:call-template> 256 </xsl:template> 257 258 259 260 <!-- Identification. --> 261 262 <xsl:template match="property[@name='name']"> 263 </xsl:template> 264 265 266 267 <!-- Labels and values. --> 268 269 <xsl:template match="property[@name='text']"> 270 </xsl:template> 271 272 273 274 <!-- Captions. --> 275 276 <xsl:template match="property[@name='caption']"> 277 </xsl:template> 278 279 280 281 <!-- Copy attributes. --> 282 283 <xsl:template match="@*"> 284 <xsl:copy> 285 <xsl:apply-templates select="node()"/> 286 </xsl:copy> 287 </xsl:template> 288 289 </xsl:stylesheet>