~vcs-imports/xena/trunk

« back to all changes in this revision

Viewing changes to ext/src/xalan-j_2_7_1/src/org/apache/xalan/lib/sql/package.html

  • 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
<!--
 
2
 * Licensed to the Apache Software Foundation (ASF) under one
 
3
 * or more contributor license agreements. See the NOTICE file
 
4
 * distributed with this work for additional information
 
5
 * regarding copyright ownership. The ASF licenses this file
 
6
 * to you under the Apache License, Version 2.0 (the  "License");
 
7
 * you may not use this file except in compliance with the License.
 
8
 * You may obtain a copy of the License at
 
9
 *
 
10
 *     http://www.apache.org/licenses/LICENSE-2.0
 
11
 *
 
12
 * Unless required by applicable law or agreed to in writing, software
 
13
 * distributed under the License is distributed on an "AS IS" BASIS,
 
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 * See the License for the specific language governing permissions and
 
16
 * limitations under the License.
 
17
-->
 
18
<!-- $Id: package.html,v 1.2 2009/12/10 03:18:45 matthewoliver Exp $ -->
 
19
<html>
 
20
  <title>Xalan SQL Extension</title>
 
21
  <body>
 
22
<p>Provides extension functions for connecting to a JDBC data source, executing a query,
 
23
and working incrementally through a "streamable" result set. Streaming (reuse of a single row node to traverse the result set) is the default mode of operation. If you want unlimited access to the entire result set, you can cache the query result set (1 row node for each row in the result set).</p>
 
24
<p><em>If you use streaming mode (the default), you can only access row elements one at a time moving forward through the result set. The use of XPath expressions in your stylesheet, for example, that attempt to return nodes from the result set in any other manner may produce unpredictable results.</em></p>   
 
25
    <p>XConnection provides three extension functions that you can use in your stylesheet.</p>
 
26
    <ol>
 
27
      <li><p>new() -- Use one of the XConnection constructors to connect to a data source, and return an XConnection
 
28
       object.</p></li>
 
29
      <li><p>query() -- Use the XConnection object query() method to return a "streamable" result set in the form of a row-set
 
30
       node. Work your way through the row-set one row at a time. The same row element is used over and over again, so you can
 
31
       begin "transforming" the row-set before the entire result set has been returned.</p></li>
 
32
      <li>close() -- Use the XConnection object close() method to terminate the connection.</li>      
 
33
    </ol>
 
34
    <p>The query() extension function returns a Document node that contains (as needed) an array of column-header elements, 
 
35
    a single row element that is used repeatedly, and an array of col elements. Each column-header element (one per column in the
 
36
    row-set) contains an attribute (ColumnAttribute) for each of the column descriptors in the ResultSetMetaData object. 
 
37
    Each col element contains a text node with a textual representation of the value for that column in the current row.</p>
 
38
    <h2>Example</h2>
 
39
    <p>This example displays the result set from a table in a sample InstantDB database.</p>
 
40
<pre>&lt;?xml version="1.0"?&gt;
 
41
&lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
42
                version="1.0"
 
43
                xmlns:sql="org.apache.xalan.lib.sql.XConnection"
 
44
                extension-element-prefixes="sql"&gt;
 
45
  &lt;xsl:output method="html" indent="yes"/&gt;
 
46
  &lt;xsl:param name="query" select="'SELECT * FROM import1'"/&gt;
 
47
 
 
48
  &lt;xsl:template match="/"&gt;
 
49
    &lt;!-- 1. Make the connection --&gt;
 
50
    &lt;xsl:variable name="products"
 
51
                  select="sql:new('org.enhydra.instantdb.jdbc.idbDriver',
 
52
                                'jdbc:idb:D:\instantdb\Examples\sample.prp')"/&gt;
 
53
    &lt;HTML&gt;
 
54
      &lt;HEAD&gt;
 
55
      &lt;/HEAD&gt;
 
56
      &lt;BODY&gt;
 
57
        &lt;TABLE border="1"&gt;
 
58
        &lt;!--2. Execute the query --&gt;
 
59
        &lt;xsl:variable name="table" select='sql:query($products, $query)'/&gt;
 
60
          &lt;TR&gt;
 
61
          &lt;!-- Get column-label attribute from each column-header--&gt;
 
62
          &lt;xsl:for-each select="$table/sql/metadata/column-header"&gt;
 
63
            &lt;TH&gt;&lt;xsl:value-of select="@column-label"/&gt;&lt;/TH&gt;
 
64
          &lt;/xsl:for-each&gt;
 
65
          &lt;/TR&gt;
 
66
          &lt;xsl:apply-templates select="$table/sql/row-set/row"/&gt;
 
67
          &lt;xsl:text&gt;&amp;#10;&lt;/xsl:text&gt;
 
68
        &lt;/TABLE&gt;
 
69
      &lt;/BODY&gt;
 
70
    &lt;/HTML&gt; 
 
71
    &lt;!-- 3. Close the connection --&gt;
 
72
    &lt;xsl:value-of select="sql:close($products)"/&gt;
 
73
  &lt;/xsl:template&gt;
 
74
 
 
75
  &lt;xsl:template match="row"&gt;
 
76
        &lt;TR&gt;
 
77
          &lt;xsl:apply-templates select="col"/&gt;
 
78
        &lt;/TR&gt;
 
79
  &lt;/xsl:template&gt;
 
80
 
 
81
  &lt;xsl:template match="col"&gt;
 
82
    &lt;TD&gt;
 
83
      &lt;!-- Here is the column data -->
 
84
      &lt;xsl:value-of select="text()"/>
 
85
    &lt;/TD>
 
86
  &lt;/xsl:template>
 
87
 
 
88
&lt;/xsl:stylesheet&gt;
 
89
</pre>    
 
90
 </body>
 
91
</html>