<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:data="http://www.huditsch.bkf.at/XHTML-XForms" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xsldoc="http://www.bacman.net/XSLdoc" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" exclude-result-prefixes="xsldoc">
  <!-- =================================================================  -->
  <!--                                                                    -->
  <!-- This Stylesheet was designed to transform XHTML forms into valid   -->
  <!-- XForms components according to the W3C XForms 1.0 Recommendation   -->
  <!--                                                                    -->
  <!-- Author: Roman Huditsch, roman.huditsch@bkf.at                      -->
  <!-- Acknowledgments: David Landwehr, david.landwehr@solidapp.com       -->
  <!--                                                                    -->
  <!-- =================================================================  -->
  <xsl:output method="xhtml" version="1.0" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
  <xsldoc:author>Roman Huditsch</xsldoc:author>
  <xsldoc:date>February 28, 2006</xsldoc:date>
  <xsldoc:version>Version Beta v0.96</xsldoc:version>
  <xsl:strip-space elements="*"/>
  <!-- ===================================================================  -->
  <!-- Per default all existing nodes should be copied into the result      -->
  <!-- document                                                             -->
  <!-- ===================================================================  -->
  <xsl:template match="node() | @*">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Process <html> root element                                          -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:html">
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:data="http://www.huditsch.bkf.at/XHTML-XForms" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
      <xsl:apply-templates select="*"/>
    </html>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Create an xforms model within xhtml:head                             -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:head">
    <xsl:copy>
      <xsl:copy-of select="@* | *"/>
      <xsl:apply-templates select="//xhtml:form" mode="model"/>
    </xsl:copy>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Create an xforms model for each <form> element                       -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:form" mode="model">
    <xforms:model id="model{position()}">
      <!-- ===================================================================  -->
      <!-- Include XForms instance element                                      -->
      <!-- ===================================================================  -->
      <xforms:instance id="formData{position()}">
        <instance xmlns="">
          <xsl:apply-templates select=".//xhtml:input[(@type='radio' and not(@name eq preceding-sibling::xhtml:input[@type='radio'][1]/@name)) or (@type='checkbox' and not(@name eq preceding-sibling::xhtml:input[@type='checkbox'][1]/@name)) or @type='text' or @type='file'] | .//xhtml:select | .//xhtml:textarea" mode="instance"/>
        </instance>
      </xforms:instance>
      <!-- ===================================================================  -->
      <!-- XForms submission                                                    -->
      <!-- ===================================================================  -->
      <xforms:submission action="{@action}" method="{if (@method) then @method else 'post'}" id="{if (@id) then @id else concat('s', position())}"/>
      <!-- ===================================================================  -->
      <!-- Include eMail data validation if necessary                           -->
      <!-- ===================================================================  -->
      <xsl:if test=".//@name[lower-case(.)]=('email', 'e-mail')">
        <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.huditsch.bkf.at/XHTML-XForms" targetNamespace="http://www.huditsch.bkf.at/XHTML-XForms" elementFormDefault="qualified">
          <xs:simpleType name="email">
            <xs:restriction base="xs:string">
              <xs:pattern value="[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{{-~]+(\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{{-~]+)*@[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{{-~]+(\.[A-Za-z0-9!#-'\*\+\-/=\?\^_`\{{-~]+)*"/>
            </xs:restriction>
          </xs:simpleType>
        </xs:schema>
      </xsl:if>
    </xforms:model>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Create XForms instance elements                                      -->
  <!-- ===================================================================  -->
  <xsl:template match="*" mode="instance">
    <xsl:choose>
      <xsl:when test="@id">
        <xsl:element name="{@id}">
          <!-- ===================================================================  -->
          <!-- Reference a specific datatype if necessary                           -->
          <!-- ===================================================================  -->
          <xsl:if test="lower-case(@id)='email' or lower-case(@id)='e-mail'">
            <xsl:attribute name="xsi:type">
              <xsl:text>data:email</xsl:text>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="@type='file'">
            <xsl:attribute name="xsi:type">
              <xsl:text>xs:base64Binary</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="filename"/>
            <xsl:attribute name="mediatype"/>
          </xsl:if>
          <!-- ===================================================================  -->
          <!-- Include default values if available                                  -->
          <!-- ===================================================================  -->
          <xsl:if test="@value[string(.)]">
            <xsl:value-of select="@value"/>
          </xsl:if>
        </xsl:element>
      </xsl:when>
      <xsl:when test="@name and not(@id)">
        <xsl:element name="{@name}">
          <!-- ===================================================================  -->
          <!-- Reference a specific datatype if necessary                           -->
          <!-- ===================================================================  -->
          <xsl:if test="lower-case(@name)='email' or lower-case(@name)='e-mail'">
            <xsl:attribute name="xsi:type">
              <xsl:text>data:email</xsl:text>
            </xsl:attribute>
          </xsl:if>
          <xsl:if test="@type='file'">
            <xsl:attribute name="xsi:type">
              <xsl:text>xs:base64Binary</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="filename"/>
            <xsl:attribute name="mediatype"/>
          </xsl:if>
          <!-- ===================================================================  -->
          <!-- Include default values if available                                  -->
          <!-- ===================================================================  -->
          <xsl:if test="@value[string(.)]">
            <xsl:value-of select="@value"/>
          </xsl:if>
        </xsl:element>
      </xsl:when>
      <xsl:otherwise>
        <xsl:element name="{concat(local-name(.), position())}">
          <!-- ===================================================================  -->
          <!-- Reference a specific datatype if necessary                           -->
          <!-- ===================================================================  -->
          <xsl:if test="@type='file'">
            <xsl:attribute name="xsi:type">
              <xsl:text>xs:base64Binary</xsl:text>
            </xsl:attribute>
            <xsl:attribute name="filename"/>
            <xsl:attribute name="mediatype"/>
          </xsl:if>
          <!-- ===================================================================  -->
          <!-- Include default values if available                                  -->
          <!-- ===================================================================  -->
          <xsl:if test="@value[string(.)]">
            <xsl:value-of select="@value"/>
          </xsl:if>
        </xsl:element>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Create an xforms group for each <form> elemtent                      -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:form">
    <xsl:variable name="count" select="count(preceding::xhtml:form)+1" as="xs:integer"/>
    <xforms:group ref="instance('formData{$count}')" model="model{$count}">
      <xsl:apply-templates/>
    </xforms:group>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Select - single                                                 -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:select[not(@multiple)]">
    <xforms:select1 appearance="minimal">
      <xsl:apply-templates select="@accesskey | @tabindex | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
      <!-- ===================================================================  -->
      <!-- Create <item> elements                                               -->
      <!-- ===================================================================  -->
      <xsl:apply-templates select="*"/>
    </xforms:select1>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Select - items                                                  -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:option">
    <xforms:item>
      <xforms:label>
        <xsl:choose>
          <xsl:when test="@label">
            <xsl:value-of select="@label"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="."/>
          </xsl:otherwise>
        </xsl:choose>
      </xforms:label>
      <xforms:value>
        <xsl:choose>
          <xsl:when test="@value">
            <xsl:value-of select="@value"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="translate(., ' ', '_')"/>
          </xsl:otherwise>
        </xsl:choose>
      </xforms:value>
    </xforms:item>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Select - optgroup                                               -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:optgroup">
    <xforms:choices>
      <xforms:label>
        <xsl:value-of select="@label"/>
      </xforms:label>
      <xsl:apply-templates select="*"/>
    </xforms:choices>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Select - multiple                                               -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:select[@multiple]">
    <xforms:select appearance="compact">
      <xsl:apply-templates select="@accesskey | @tabindex | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
      <!-- ===================================================================  -->
      <!-- Create <item> elements                                               -->
      <!-- ===================================================================  -->
      <xsl:apply-templates select="*"/>
    </xforms:select>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Radio buttons                                                   -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='radio' and not(@name eq preceding-sibling::xhtml:input[@type='radio'][1]/@name)]">
    <xforms:select1 appearance="full">
      <xsl:apply-templates select="@accesskey | @tabindex | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
      <!-- ===================================================================  -->
      <!-- Create <item> elements                                               -->
      <!-- ===================================================================  -->
      <xforms:item>
        <xforms:label>
          <xsl:value-of select="normalize-space(following::text()[1])"/>
        </xforms:label>
        <xforms:value>
          <xsl:value-of select="@value"/>
        </xforms:value>
      </xforms:item>
      <xsl:apply-templates select="following-sibling::xhtml:input[@type='radio' and @name=current()/@name]" mode="output"/>
    </xforms:select1>
  </xsl:template>
  <xsl:template match="xhtml:input[@type='radio' and @name=preceding-sibling::xhtml:input[@type='radio']/@name]" mode="output">
    <xforms:item>
      <xforms:label>
        <xsl:value-of select="normalize-space(following::text()[1])"/>
      </xforms:label>
      <xforms:value>
        <xsl:value-of select="@value"/>
      </xforms:value>
    </xforms:item>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI -Checkboxes                                                       -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='checkbox' and not(@name eq preceding-sibling::xhtml:input[@type='checkbox'][1]/@name)]">
    <xforms:select appearance="full">
      <xsl:apply-templates select="@accesskey | @tabindex | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
      <!-- ===================================================================  -->
      <!-- Create <item> elements                                               -->
      <!-- ===================================================================  -->
      <xforms:item>
        <xforms:label>
          <xsl:value-of select="normalize-space(following::text()[1])"/>
        </xforms:label>
        <xforms:value>
          <xsl:value-of select="@value"/>
        </xforms:value>
      </xforms:item>
      <xsl:apply-templates select="following-sibling::xhtml:input[@type='checkbox' and @name=current()/@name]" mode="output"/>
    </xforms:select>
  </xsl:template>
  <xsl:template match="xhtml:input[@type='checkbox' and @name=preceding-sibling::xhtml:input[@type='checkbox']/@name]" mode="output">
    <xforms:item>
      <xforms:label>
        <xsl:value-of select="normalize-space(following::text()[1])"/>
      </xforms:label>
      <xforms:value>
        <xsl:value-of select="@value"/>
      </xforms:value>
    </xforms:item>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Button                                                          -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:button | xhtml:input[@type='button']">
    <xforms:trigger>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <xforms:label>
        <xsl:value-of select="@value"/>
      </xforms:label>
      <xsl:apply-templates select="@onclick"/>
      <xsl:apply-templates select="*"/>
    </xforms:trigger>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Image Buttons                                                   -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='image']">
    <xforms:trigger>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <xforms:label>
        <xsl:value-of select="@value"/>
      </xforms:label>
      <xsl:apply-templates select="@onclick"/>
      <xhtml:img src="{@src}">
        <xsl:apply-templates select="@alt"/>
      </xhtml:img>
    </xforms:trigger>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Submit                                                          -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='submit'] | xhtml:button[@type='submit']">
    <xforms:submit submission="{if (ancestor::xhtml:form/@id) then ancestor::xhtml:form/@id else concat('s', count(preceding::xhtml:form)+1)}">
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <xforms:label>
        <xsl:value-of select="if (@value[string(.)]) then @value else 'Submit'"/>
      </xforms:label>
    </xforms:submit>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Reset                                                           -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='reset'] | xhtml:button[@type='reset']">
    <xforms:trigger>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <xforms:label>
        <xsl:value-of select="if (@value[string(.)]) then @value else 'Reset'"/>
      </xforms:label>
      <xforms:reset ev:event="DOMActivate" model="model{count(preceding::xhtml:form)+1}"/>
    </xforms:trigger>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Text Input                                                      -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='text']">
    <xforms:input>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
    </xforms:input>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Password Input                                                  -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='pasword']">
    <xforms:secret>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
    </xforms:secret>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - File Input                                                      -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:input[@type='file']">
    <xforms:upload mediatype="{@accept}">
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
      <xforms:filename ref="@filename"/>
      <xforms:mediatype ref="@mediatype"/>
    </xforms:upload>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - Textarea                                                        -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:textarea">
    <xforms:textarea>
      <xsl:apply-templates select="@accesskey | @tabindex | @size | @style | @id"/>
      <!-- ===================================================================  -->
      <!-- Create Reference to the XForms instance                              -->
      <!-- ===================================================================  -->
      <xsl:attribute name="ref">
        <xsl:choose>
          <xsl:when test="@id">
            <xsl:value-of select="@id"/>
          </xsl:when>
          <xsl:when test="@name and not(@id)">
            <xsl:value-of select="@name"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:value-of select="concat(local-name(.), position())"/>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
      <xforms:label>
        <xsl:apply-templates select="preceding::xhtml:label[@for=current()/@id and not(parent::xhtml:td)] | preceding-sibling::xhtml:*[1][local-name()='label']" mode="output"/>
      </xforms:label>
    </xforms:textarea>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - fieldset                                                        -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:fieldset">
    <xforms:group>
      <xsl:apply-templates/>
    </xforms:group>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - label (Labels are displayed if they are not a child of          -->
  <!-- <xhtml:td>, have a @for or are an immediate sibling of an XForms     -->
  <!-- element                                                              -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:label" mode="output">
    <xsl:value-of select="."/>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - legend                                                          -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:legend">
    <xforms:label>
      <xsl:value-of select="."/>
    </xforms:label>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - @id, @tabindex, @accesskey, @alt                                -->
  <!-- ===================================================================  -->
  <xsl:template match="@id | @tabindex | @accesskey | @alt">
    <xsl:copy/>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - @style                                                          -->
  <!-- ===================================================================  -->
  <xsl:template match="@style">
    <xsl:attribute name="style">
      <xsl:value-of select="."/>
      <xsl:if test="../@size">
        <xsl:value-of select="if (ends-with(., ';')) then (concat('width: ', number(../@size)*6, 'px')) else (concat('; width: ', number(../@size)*6, 'px'))"/>
      </xsl:if>
    </xsl:attribute>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - @size                                                           -->
  <!-- ===================================================================  -->
  <xsl:template match="@size">
    <xsl:if test="not(../@style)">
      <xsl:attribute name="style">
        <xsl:value-of select="concat('width: ', number(.)*6, 'px')"/>
      </xsl:attribute>
    </xsl:if>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- UI - @onclick                                                        -->
  <!-- ===================================================================  -->
  <xsl:template match="@onclick">
    <ev:listener event="DOMActivate" handler="{if (contains(lower-case(.), 'javascript:')) then (.) else (concat('javascript:', .))}"/>
  </xsl:template>
  <!-- ===================================================================  -->
  <!-- Suppressed elements                                                   -->
  <!-- ===================================================================  -->
  <xsl:template match="xhtml:label[(@for or following-sibling::xforms:*) and not(parent::xhtml:td)] | xhtml:input[(@type='radio' or @type='checkbox') and @name=preceding-sibling::xhtml:input[@type='radio' or @type='checkbox']/@name] | text()[preceding::*[1][@type='radio' or @type='checkbox']]"/>
</xsl:stylesheet>
