Hide one column, provide infos in details box
[misc/kostenrechnung] / lib / rico / ricoSimpleGrid2xl.xsl
1 <xsl:stylesheet version="1.0"
2   xmlns="urn:schemas-microsoft-com:office:spreadsheet"
3   xmlns:xhtml="http://www.w3.org/1999/xhtml"
4   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
5         xmlns:msxsl="urn:schemas-microsoft-com:xslt"
6         xmlns:o="urn:schemas-microsoft-com:office:office"
7         xmlns:x="urn:schemas-microsoft-com:office:excel"
8   xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
9
10 <xsl:output method="xml" indent="yes" omit-xml-declaration="no" media-type="application/xml"/>
11
12 <xsl:template match="/">
13   <xsl:processing-instruction name="mso-application">
14   <xsl:text>progid="Excel.Sheet"</xsl:text> 
15   </xsl:processing-instruction>
16
17   <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
18    xmlns:o="urn:schemas-microsoft-com:office:office"
19    xmlns:x="urn:schemas-microsoft-com:office:excel"
20    xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
21    xmlns:html="http://www.w3.org/TR/REC-html40">
22
23  <Styles>
24   <Style ss:ID="Default" ss:Name="Normal">
25    <Alignment ss:Vertical="Bottom"/>
26    <Borders/>
27    <Font/>
28    <Interior/>
29    <NumberFormat/>
30    <Protection/>
31   </Style>
32   <Style ss:ID="s21">
33    <Font ss:Bold="1"/>
34    <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
35   </Style>
36   <Style ss:ID="s22">
37    <Alignment ss:Horizontal="Left" ss:Vertical="Bottom"/>
38    <Font ss:Bold="1"/>
39    <Interior ss:Color="#99CCFF" ss:Pattern="Solid"/>
40   </Style>
41   <Style ss:ID="s23" ss:Name="Currency">
42    <NumberFormat
43     ss:Format="_(&quot;$&quot;* #,##0.00_);_(&quot;$&quot;* \(#,##0.00\);_(&quot;$&quot;* &quot;-&quot;??_);_(@_)"/>
44   </Style>
45   <Style ss:ID="s24">
46    <NumberFormat ss:Format="_(* #,##0.00_);_(* \(#,##0.00\);_(* &quot;-&quot;??_);_(@_)"/>
47   </Style>
48   <Style ss:ID="s25">
49    <Alignment ss:Horizontal="Center" ss:Vertical="Bottom"/>
50   </Style>
51  </Styles>
52
53   <xsl:apply-templates mode="top"/> 
54
55   </Workbook>
56 </xsl:template>
57
58
59 <xsl:template match="*" mode="top">
60   <xsl:choose>
61
62   <xsl:when test="xhtml:table[@class='ricoSimpleGrid']">
63   <xsl:apply-templates mode="grid"/> 
64   </xsl:when>
65
66   <xsl:otherwise>
67   <xsl:apply-templates select="*" mode="top"/> 
68   </xsl:otherwise>
69   
70   </xsl:choose>
71 </xsl:template>
72
73
74 <xsl:template match="*" mode="grid">
75
76   <xsl:choose>
77   
78   <xsl:when test="xhtml:thead">
79   <xsl:call-template name="processTable">
80   <xsl:with-param name="id" select="@id"/>
81   <xsl:with-param name="headRows" select="xhtml:thead/xhtml:tr"/>
82   <xsl:with-param name="bodyRows" select="xhtml:tbody/xhtml:tr"/>
83   </xsl:call-template>
84   </xsl:when>
85   
86   <xsl:when test="xhtml:tbody">
87   <xsl:call-template name="processTable">
88   <xsl:with-param name="id" select="@id"/>
89   <xsl:with-param name="headRows" select="xhtml:tbody/xhtml:tr[1]"/>
90   <xsl:with-param name="bodyRows" select="xhtml:tbody/xhtml:tr[position() &gt; 1]"/>
91   </xsl:call-template>
92   </xsl:when>
93   
94   <xsl:otherwise>
95   <xsl:call-template name="processTable">
96   <xsl:with-param name="id" select="@id"/>
97   <xsl:with-param name="headRows" select="xhtml:tr[1]"/>
98   <xsl:with-param name="bodyRows" select="xhtml:tr[position() &gt; 1]"/>
99   </xsl:call-template>
100   </xsl:otherwise>
101   
102   </xsl:choose>
103
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  <Worksheet>
115  <xsl:attribute name="ss:Name">
116    <xsl:value-of select='$id'/>
117  </xsl:attribute>
118   <Table>
119
120   <xsl:apply-templates select="$headRows" mode="convertHeadRow"/>
121   <xsl:apply-templates select="$bodyRows" mode="convertBodyRow"/>
122
123   </Table>
124  </Worksheet>
125
126 </xsl:template>
127
128
129 <xsl:template match="*" mode="convertHeadRow">
130    <Row>
131     <xsl:apply-templates select="xhtml:td | xhtml:th" mode="convertHeadCell"/>
132    </Row>
133 </xsl:template>
134
135
136 <xsl:template match="*" mode="convertHeadCell">
137   <xsl:element name="Cell">
138   <xsl:attribute name="ss:StyleID">s22</xsl:attribute>
139   <xsl:if test="@colspan">
140   <xsl:attribute name="ss:MergeAcross"><xsl:value-of select="number(@colspan)-1"/></xsl:attribute>
141   </xsl:if>
142     <Data ss:Type="String">
143     <xsl:value-of select="."/>
144     </Data>
145   </xsl:element>
146 </xsl:template>
147
148
149 <xsl:template match="*" mode="convertBodyRow">
150    <Row>
151     <xsl:apply-templates select="xhtml:td | xhtml:th" mode="convertBodyCell"/>
152    </Row>
153 </xsl:template>
154
155
156 <xsl:template match="*" mode="convertBodyCell">
157     <Cell><Data ss:Type="String"><xsl:value-of select="."/></Data></Cell>
158 </xsl:template>
159
160 </xsl:stylesheet>