Hide hour sum per default
[misc/kostenrechnung] / lib / rico / ricoSimpleGrid.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0"
4   xmlns:xhtml="http://www.w3.org/1999/xhtml"
5   xmlns="http://www.w3.org/1999/xhtml"
6   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
7   xmlns:xs="http://www.w3.org/2001/XMLSchema"
8   xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
9   xmlns:xdt="http://www.w3.org/2005/02/xpath-datatypes"
10 exclude-result-prefixes="xhtml xsl fn xs xdt">
11
12 <xsl:output
13 omit-xml-declaration="yes"
14 method="html"
15 doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
16 doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/>
17
18 <xsl:attribute-set name="ricoTable"> 
19   <xsl:attribute name="cellspacing">0</xsl:attribute> 
20   <xsl:attribute name="cellpadding">0</xsl:attribute> 
21 </xsl:attribute-set> 
22
23 <!-- the identity template -->
24
25 <xsl:template match="*">
26   <xsl:copy>
27   <xsl:copy-of select="@*"/>
28   <xsl:apply-templates/>
29   </xsl:copy>
30 </xsl:template>
31
32
33 <!-- in some cases, IE was duplicating br tags -->
34
35 <xsl:template match="xhtml:br">
36   <xsl:copy>
37   <xsl:copy-of select="@*"/>
38   </xsl:copy>
39 </xsl:template>
40
41
42 <!-- Transform head section -->
43
44 <xsl:template match="xhtml:head">
45   <xsl:copy>
46   <xsl:apply-templates mode="head"/>
47 <script type="text/javascript">
48 //<![CDATA[
49 if (typeof ricoInit!='undefined') {
50   if (window.addEventListener)
51     window.addEventListener('load', ricoInit, false);
52   else if (window.attachEvent)
53     window.attachEvent('onload', ricoInit);
54 }
55 // ]]>
56 </script>
57   </xsl:copy>
58 </xsl:template>
59
60 <xsl:template match="*[name()!='script']" mode="head">
61   <xsl:copy>
62   <xsl:copy-of select="@*|node()"/>
63   </xsl:copy>
64 </xsl:template>
65
66 <xsl:template match="xhtml:script" mode="head">
67   <xsl:copy>
68   <xsl:copy-of select="@*"/>
69   <xsl:value-of select="." disable-output-escaping="yes"/>
70   </xsl:copy>
71 </xsl:template>
72
73
74 <!-- Transform tables with class ricoSimpleGrid -->
75   
76 <xsl:template match="xhtml:table[@class='ricoSimpleGrid']">
77 <xsl:choose>
78
79 <xsl:when test="xhtml:thead">
80 <xsl:call-template name="processTable">
81 <xsl:with-param name="id" select="@id"/>
82 <xsl:with-param name="headRows" select="xhtml:thead/xhtml:tr"/>
83 <xsl:with-param name="bodyRows" select="xhtml:tbody/xhtml:tr"/>
84 </xsl:call-template>
85 </xsl:when>
86
87 <xsl:when test="xhtml:tbody">
88 <xsl:call-template name="processTable">
89 <xsl:with-param name="id" select="@id"/>
90 <xsl:with-param name="headRows" select="xhtml:tbody/xhtml:tr[1]"/>
91 <xsl:with-param name="bodyRows" select="xhtml:tbody/xhtml:tr[position() &gt; 1]"/>
92 </xsl:call-template>
93 </xsl:when>
94
95 <xsl:otherwise>
96 <xsl:call-template name="processTable">
97 <xsl:with-param name="id" select="@id"/>
98 <xsl:with-param name="headRows" select="xhtml:tr[1]"/>
99 <xsl:with-param name="bodyRows" select="xhtml:tr[position() &gt; 1]"/>
100 </xsl:call-template>
101 </xsl:otherwise>
102
103 </xsl:choose>
104 </xsl:template>
105
106
107 <!-- Perform the actual table transformation -->
108   
109 <xsl:template name="processTable">
110 <xsl:param name="id" />
111 <xsl:param name="headRows" />
112 <xsl:param name="bodyRows" />
113
114 <xsl:variable name="headIdx">
115 <xsl:choose>
116 <xsl:when test="$headRows[@class='ricoHeading']">
117 <xsl:value-of select="count($headRows[@class='ricoHeading']/preceding-sibling::*)+1"/>
118 </xsl:when>
119 <xsl:otherwise>
120 <xsl:value-of select="count($headRows)"/>
121 </xsl:otherwise>
122 </xsl:choose>
123 </xsl:variable>
124
125 <xsl:variable name="headMain" select="$headRows[position()=$headIdx]"/>
126 <xsl:variable name="headCols" select="$headMain/xhtml:th | $headMain/xhtml:td"/>
127
128 <!--
129 <p><xsl:value-of select="$id"/>
130 <br />headRowCnt: <xsl:value-of select="count($headRows)"/>
131 <br />headIdx: <xsl:value-of select="$headIdx"/>
132 <br />bodyRowCnt: <xsl:value-of select="count($bodyRows)"/>
133 </p>
134 -->
135
136 <xsl:element name="div">
137 <xsl:attribute name="id"><xsl:value-of select="concat($id,'_outerDiv')"/></xsl:attribute>
138 <xsl:attribute name="class">ricoLG_outerDiv</xsl:attribute>
139 <xsl:attribute name="onload"></xsl:attribute>
140
141 <!-- Create frozen (left) pane -->
142
143 <xsl:element name="div">
144 <xsl:attribute name="id"><xsl:value-of select="concat($id,'_frozenTabsDiv')"/></xsl:attribute>
145 <xsl:attribute name="class">ricoLG_frozenTabsDiv</xsl:attribute>
146
147 <xsl:call-template name="convertTHead">
148 <xsl:with-param name="rows" select="$headRows"/>
149 <xsl:with-param name="headIdx" select="$headIdx"/>
150 <xsl:with-param name="frozen" select="1"/>
151 <xsl:with-param name="id" select="concat($id,'_tab0h')"/>
152 </xsl:call-template>
153
154 <xsl:call-template name="convertTBody">
155 <xsl:with-param name="rows" select="$bodyRows"/>
156 <xsl:with-param name="cols" select="$headCols"/>
157 <xsl:with-param name="id" select="concat($id,'_tab0')"/>
158 <xsl:with-param name="frozen" select="1"/>
159 </xsl:call-template>
160
161 </xsl:element>
162
163 <xsl:element name="div">
164 <xsl:attribute name="id"><xsl:value-of select="concat($id,'_innerDiv')"/></xsl:attribute>
165 <xsl:attribute name="class">ricoLG_innerDiv</xsl:attribute>
166
167 <xsl:element name="div">
168 <xsl:attribute name="id"><xsl:value-of select="concat($id,'_scrollTabsDiv')"/></xsl:attribute>
169 <xsl:attribute name="class">ricoLG_scrollTabsDiv</xsl:attribute>
170
171 <xsl:call-template name="convertTHead">
172 <xsl:with-param name="rows" select="$headRows"/>
173 <xsl:with-param name="headIdx" select="$headIdx"/>
174 <xsl:with-param name="frozen" select="0"/>
175 <xsl:with-param name="id" select="concat($id,'_tab1h')"/>
176 </xsl:call-template>
177
178 </xsl:element>
179 </xsl:element>
180
181 <xsl:element name="div">
182 <xsl:attribute name="id"><xsl:value-of select="concat($id,'_scrollDiv')"/></xsl:attribute>
183 <xsl:attribute name="class">ricoLG_scrollDiv</xsl:attribute>
184
185 <xsl:call-template name="convertTBody">
186 <xsl:with-param name="rows" select="$bodyRows"/>
187 <xsl:with-param name="cols" select="$headCols"/>
188 <xsl:with-param name="id" select="concat($id,'_tab1')"/>
189 <xsl:with-param name="frozen" select="0"/>
190 </xsl:call-template>
191 </xsl:element>
192
193 </xsl:element>
194
195 </xsl:template>
196
197
198 <!-- Convert thead section -->
199
200 <xsl:template name="convertTHead">
201 <xsl:param name = "rows" />
202 <xsl:param name = "headIdx" />
203 <xsl:param name = "frozen" />
204 <xsl:param name = "id" />
205 <xsl:element name="table" use-attribute-sets="ricoTable">
206 <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
207 <xsl:attribute name="class">ricoLG_table ricoLG_top
208 <xsl:if test="$frozen">ricoLG_left</xsl:if>
209 <xsl:if test="not($frozen)">ricoLG_right</xsl:if>
210 </xsl:attribute>
211 <xsl:element name="thead">
212   <xsl:for-each select="$rows">
213     <xsl:choose>
214     <xsl:when test="position() = $headIdx">
215       <xsl:apply-templates select="." mode="convertHeadRow">
216       <xsl:with-param name="id" select="concat($id,'_main')"/>
217       <xsl:with-param name="frozen" select="$frozen"/>
218       </xsl:apply-templates>
219     </xsl:when>
220     <xsl:otherwise>
221       <xsl:apply-templates select="." mode="convertHeadRow">
222       <xsl:with-param name="id" select="concat($id,'_',position())"/>
223       <xsl:with-param name="frozen" select="$frozen"/>
224       </xsl:apply-templates>
225     </xsl:otherwise>
226     </xsl:choose>
227   </xsl:for-each>
228 </xsl:element>
229 <tbody />
230 </xsl:element>
231 </xsl:template>
232
233
234 <xsl:template match="*" mode="convertHeadRow">
235 <xsl:param name = "id" />
236 <xsl:param name = "frozen" />
237   <xsl:variable name="class" select="@class"/>
238   <xsl:variable name="cells" select="xhtml:th | xhtml:td"/>
239   <xsl:element name="tr">
240   <xsl:if test="$id">
241     <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
242   </xsl:if>
243   <xsl:attribute name="class">ricoLG_hdg <xsl:value-of select="$class"/></xsl:attribute>
244   <xsl:for-each select="$cells[@class='ricoFrozen' and $frozen or not(@class='ricoFrozen') and not($frozen)]">
245       <xsl:copy>
246         <xsl:copy-of select="@*"/>
247         <div class='ricoLG_col' style='width:100px'>
248           <xsl:element name="div">
249           <xsl:attribute name="class">ricoLG_cell <xsl:value-of select="@class"/></xsl:attribute>
250             <xsl:copy-of select="* | @*[name()!='class'] | text()"/>
251           </xsl:element>
252         </div>
253       </xsl:copy>
254     </xsl:for-each>
255   </xsl:element>
256 </xsl:template>
257
258
259 <!-- Convert tbody section -->
260
261 <xsl:template name="convertTBody">
262 <xsl:param name = "rows" />
263 <xsl:param name = "cols" />
264 <xsl:param name = "id" />
265 <xsl:param name = "frozen" />
266 <xsl:element name="table" use-attribute-sets="ricoTable">
267 <xsl:attribute name="id"><xsl:value-of select="$id"/></xsl:attribute>
268 <xsl:attribute name="class">ricoLG_table ricoLG_bottom
269 <xsl:if test="$frozen">ricoLG_left</xsl:if>
270 <xsl:if test="not($frozen)">ricoLG_right</xsl:if>
271 </xsl:attribute> 
272 <xsl:element name="tbody">
273   <tr>
274   <xsl:for-each select="$cols">
275     <xsl:if test="@class='ricoFrozen' and $frozen or not(@class='ricoFrozen') and not($frozen)">
276       <xsl:variable name="colpos" select="position()"/>
277       <td>
278         <div class='ricoLG_col' style='width:100px'>
279           <xsl:for-each select="$rows">
280             <xsl:element name="div">
281             <xsl:attribute name="class">ricoLG_cell <xsl:value-of select="xhtml:td[$colpos]/@class"/></xsl:attribute>
282               <xsl:copy-of select="xhtml:td[$colpos]/* | xhtml:td[$colpos]/@*[name()!='class'] | xhtml:td[$colpos]/text()"/>
283             </xsl:element>
284           </xsl:for-each>
285         </div>
286       </td>
287     </xsl:if>
288   </xsl:for-each>
289   </tr>
290 </xsl:element>
291 </xsl:element>
292 </xsl:template>
293
294 </xsl:stylesheet>