xform.xsl 5.23 KB
Newer Older
Thitichaipun Wutthisak committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- ================= form with 'automatic' 2-column table layout ================= -->

<xsl:param name="form-border" select="'1'"/>


<xsl:template match="xform[@style='twocolumn-omit-table']">
  <xsl:apply-templates mode="twocolumn"/>
</xsl:template>

<xsl:template match="xform[@style='twocolumn']">
  <table border="{$form-border}" cellspacing="0" cellpadding="2" id="{$renderId}">
    <xsl:apply-templates select="@width"/>
    <xsl:apply-templates mode="twocolumn"/>
  </table>
</xsl:template>

<!--
wie "twocolumn", jedoch werden keine globalen stylesheet parameter verwendet
(das wuerde zu mehrfachen verwendung der renderId fuehren)
-->
<xsl:template match="xform[@style='nested']">
  <table border="1" cellspacing="0" cellpadding="2" id="{@id}">
    <xsl:apply-templates select="@width"/>
    <xsl:apply-templates mode="twocolumn"/>
  </table>
</xsl:template>

<!-- ignore hidden elements -->
<xsl:template mode="twocolumn" match="*[@hidden='true']"/>

<xsl:template mode="twocolumn" match="label|textField|password|listBox1|listBoxN|checkBox|radioButton|fileUpload">
  <xsl:call-template name="show-error"/>
  <tr>
    <td class="xform-label">
      <xsl:value-of select="@label"/>
    </td>
    <td class="xform-input">
      <xsl:apply-templates select="."/>
    </td>
  </tr>
</xsl:template>



<!-- textarea takes the whole space -->
<xsl:template mode="twocolumn" match="textArea">
  <xsl:call-template name="show-error"/>
  <tr>
    <td colspan="2" class="xform-both">
      <xsl:if test="@label">
        <xsl:value-of select="@label"/>
        <br/>
      </xsl:if>
      <xsl:apply-templates select="."/>
    </td>
  </tr>
</xsl:template>


<!-- displays a row with buttons -->
<xsl:template mode="twocolumn" match="buttons">
  <tr>
    <td colspan="2" align="right">
      <div align="right">
        <xsl:apply-templates/>
      </div>
    </td>
  </tr>
</xsl:template>


<!-- title text only -->
<xsl:template mode="twocolumn" match="title">
  <tr>
    <th colspan="2" class="xform-title">
      <!-- support both <title>blah</title> and <title value="blah"/> -->
      <xsl:value-of select="@value"/>
      <xsl:apply-templates/>
    </th>
  </tr>
</xsl:template>

<!-- subtitle text only -->
<xsl:template mode="twocolumn" match="subtitle">
  <tr>
    <th colspan="2" class="xform-subtitle">
      <!-- support both <title>blah</title> and <title value="blah"/> -->
      <xsl:value-of select="@value"/>
      <xsl:apply-templates/>
    </th>
  </tr>
</xsl:template>

<!-- title with close button(s) -->
<xsl:template mode="twocolumn" match="title[imgButton]">
  <tr>
    <th colspan="2" class="xform-title">
      <table border="0" cellspacing="0" cellpadding="0" width="100%">
        <tr>
          <th align="left" class="xform-title">
            <xsl:value-of select="@value"/>
          </th>
          <td align="right" class="xform-close-button">
            <xsl:apply-templates/>
          </td>
        </tr>
      </table>
    </th>
  </tr>
</xsl:template>


<!-- displays text in two columns -->
<xsl:template mode="twocolumn" match="text">
  <xsl:call-template name="show-error"/>
  <tr>
    <td colspan="2" class="xform-both">
      <!-- support both <text>blah</text> and <text value="blah"/> -->
      <xsl:value-of select="@value"/>
      <xsl:apply-templates/>
    </td>
  </tr>
</xsl:template>


<!-- escapes to manual layout after checking the @error attribute -->
<xsl:template mode="twocolumn" match="manual">
  <xsl:call-template name="show-error"/>
  <xsl:apply-templates/>
</xsl:template>
<!-- ignored if already in manual mode -->
<xsl:template match="manual"/>

<!-- inverse of manual -->
<xsl:template match="twocolumn">
  <xsl:call-template name="show-error"/>
  <xsl:apply-templates mode="twocolumn"/>
</xsl:template>
<!-- ignored if already in twocolumn mode -->
<xsl:template mode="twocolumn" match="twocolumn"/>

<!-- block with multiple columns -->
<xsl:template mode="twocolumn" match="multicolumn">
  <xsl:call-template name="show-error"/>
  <tr>
    <td colspan="2">
      <table>
        <tr>
          <xsl:apply-templates mode="multicolumn" select="column"/>
        </tr>
      </table>
    </td>
  </tr>
</xsl:template>
<!-- single column inside a multicolumn element -->
<xsl:template mode="multicolumn" match="column">
  <td valign="top">
    <table>
      <xsl:apply-templates mode="twocolumn"/>
    </table>
  </td>
</xsl:template>

<!-- displays a table row with error message -->
<xsl:template name="show-error">
  <xsl:if test="@error">
    <tr>
      <td colspan="2" class="xform-error">
        <xsl:value-of select="@error"/>
      </td>
    </tr>
  </xsl:if>
</xsl:template>

<xsl:template mode="twocolumn" match="errorElement">
  <xsl:call-template name="show-error"/>
</xsl:template>

<!-- =============== form without automatic layout ===================== -->

<xsl:template match="xform[@style='manual']">
  <xsl:apply-templates/>
</xsl:template>

<xsl:template match="error-list">
  <ul>
    <xsl:for-each select="//*[@error]">
      <li>
        <xsl:value-of select="@error"/>
      </li>
    </xsl:for-each>
  </ul>
</xsl:template>

<xsl:template match="error-message">
  <xsl:value-of select="//@error"/>
</xsl:template>

</xsl:stylesheet>