~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/samples/extensions/sql/streamable/pivot.xsl

  • Committer: matthewoliver
  • Date: 2009-12-10 03:18:07 UTC
  • Revision ID: vcs-imports@canonical.com-20091210031807-l086qguzdlljtkl9
Merged Xena Testing into Xena Stable for the Xena 5 release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0"?>
 
2
 
 
3
  <!--
 
4
   * Licensed to the Apache Software Foundation (ASF) under one
 
5
   * or more contributor license agreements. See the NOTICE file
 
6
   * distributed with this work for additional information
 
7
   * regarding copyright ownership. The ASF licenses this file
 
8
   * to you under the Apache License, Version 2.0 (the  "License");
 
9
   * you may not use this file except in compliance with the License.
 
10
   * You may obtain a copy of the License at
 
11
   *
 
12
   *     http://www.apache.org/licenses/LICENSE-2.0
 
13
   *
 
14
   * Unless required by applicable law or agreed to in writing, software
 
15
   * distributed under the License is distributed on an "AS IS" BASIS,
 
16
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
17
   * See the License for the specific language governing permissions and
 
18
   * limitations under the License.
 
19
  -->
 
20
 
 
21
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
22
 
 
23
                version="1.0"
 
24
 
 
25
                xmlns:sql="org.apache.xalan.lib.sql.XConnection"
 
26
 
 
27
                extension-element-prefixes="sql">
 
28
 
 
29
 
 
30
 
 
31
<xsl:output method="html" indent="yes"/>
 
32
 
 
33
 
 
34
 
 
35
<xsl:param name="driver" select="'org.apache.derby.jdbc.EmbeddedDriver'"/>
 
36
 
 
37
<xsl:param name="datasource" select="'jdbc:derby:sampleDB'"/>
 
38
 
 
39
<xsl:param name="query" select="'SELECT * FROM import1'"/>
 
40
 
 
41
 
 
42
 
 
43
<xsl:template match="/">
 
44
 
 
45
    <xsl:variable name="db" select="sql:new()"/>
 
46
 
 
47
    
 
48
 
 
49
    <!-- Connect to the database with minimal error detection -->
 
50
 
 
51
    <xsl:if test="not(sql:connect($db, $driver, $datasource))" >
 
52
 
 
53
      <xsl:message>Error Connecting to the Database</xsl:message>
 
54
 
 
55
      <xsl:copy-of select="sql:getError($db)/ext-error" />
 
56
 
 
57
    </xsl:if>
 
58
 
 
59
    
 
60
 
 
61
 
 
62
 
 
63
    <HTML>
 
64
 
 
65
      <HEAD>
 
66
 
 
67
        <TITLE>List of products</TITLE>
 
68
 
 
69
      </HEAD>
 
70
 
 
71
      <BODY>
 
72
 
 
73
      
 
74
 
 
75
      <!-- Turn off Streaming -->
 
76
 
 
77
      <xsl:value-of select="sql:setFeature($db, 'streaming', 'false')" />
 
78
 
 
79
      
 
80
 
 
81
      <xsl:variable name="table" select='sql:query($db, $query)'/>
 
82
 
 
83
      
 
84
 
 
85
      <!-- 
 
86
 
 
87
         Let's include Error Checking, the error is actually stored 
 
88
 
 
89
          in the connection since $table will be either data or null
 
90
 
 
91
       -->
 
92
 
 
93
             
 
94
 
 
95
          <xsl:if test="not($table)" >
 
96
 
 
97
                <xsl:message>Error in Query</xsl:message>
 
98
 
 
99
            <xsl:copy-of select="sql:getError($db)/ext-error" />
 
100
 
 
101
          </xsl:if>
 
102
 
 
103
          
 
104
 
 
105
      
 
106
 
 
107
      
 
108
 
 
109
        <TABLE border="1">
 
110
 
 
111
          <TR>
 
112
 
 
113
             <xsl:for-each select="$table/sql/metadata/column-header">
 
114
 
 
115
               <TH><xsl:value-of select="@column-label"/></TH>
 
116
 
 
117
             </xsl:for-each>
 
118
 
 
119
          </TR>
 
120
 
 
121
          <xsl:apply-templates select="$table/sql/row-set"/>
 
122
 
 
123
        </TABLE>
 
124
 
 
125
        
 
126
 
 
127
        <TABLE border="1">
 
128
 
 
129
 
 
130
 
 
131
        <xsl:for-each select="$table/sql/metadata/column-header">
 
132
 
 
133
        <xsl:variable name="column" select="@column-label" />
 
134
 
 
135
 
 
136
 
 
137
                <TR>
 
138
 
 
139
                <TD><TH><xsl:value-of select="$column"/></TH></TD>
 
140
 
 
141
                <xsl:apply-templates
 
142
 
 
143
                select="$table/sql/row-set/row/col[@column-label=$column]" />
 
144
 
 
145
          </TR>
 
146
 
 
147
          </xsl:for-each>
 
148
 
 
149
 
 
150
 
 
151
        </TABLE>
 
152
 
 
153
       
 
154
 
 
155
        
 
156
 
 
157
      </BODY>
 
158
 
 
159
    </HTML>
 
160
 
 
161
    <xsl:value-of select="sql:close($db)"/>
 
162
 
 
163
</xsl:template>
 
164
 
 
165
 
 
166
 
 
167
<xsl:template match="row">
 
168
 
 
169
  <TR><xsl:apply-templates select="col"/></TR>
 
170
 
 
171
</xsl:template>
 
172
 
 
173
 
 
174
 
 
175
<xsl:template match="col">
 
176
 
 
177
  <TD><xsl:value-of select="text()"/></TD>
 
178
 
 
179
</xsl:template>
 
180
 
 
181
 
 
182
 
 
183
</xsl:stylesheet>
 
 
b'\\ No newline at end of file'