sql:query

Performs a query, and returns the results of the query as a sequence of elements: each element in the return value represents one row of the query result. If you want to process the results in the stylesheet, you can write the results to a temporary tree by using the sql:query instruction as a child of xsl:variable.

Attributes

connection

expression

The database connection. The value is an expression, which must evaluate to a database connection object as returned by sql:connect.

table

{ expression }

The table to be queried (the contents of the FROM clause of the select statement).

column

{ expression }

The columns to be retrieved (the contents of the SELECT clause of the select statement). May be "*" to retrieve all columns.

where?

{ expression }

The conditions to be applied (the contents of the WHERE clause of the select statement).

row-tag?

NCName

The element name to be used to contain each row. Must be a simple name (no colon allowed); alternatively the value #auto (which is the default) indicates that element name is to be formed from the table name used in the table attribute if this is a simple NCName, failing which the element name will be "row".

column-tag?

NCName

The element name to be used to contain each column. Must be a simple name (no colon allowed); alternatively the value #auto (which is the default) indicates that column names are to be formed from the column names in the database where available. When this option is used, the database column name will be used as the XML element name, provided it is a valid NCName; if it is not, the element name will be "col" and the column name will appear as the value of its name attribute.

disable-output-escaping?

boolean

Default is no. The value yes causes the content of all rows/columns to be output as is, without converting special characters such as "<" to "&lt;". This is useful where the database contains XML or HTML markup that you want to be copied into the result document. Use this option with care, however, since it applies to all the columns retrieved, not only to those that contain XML or HTML. An alternative is to use the saxon:parse extension function to process the contents of an XML column.

Saxon availability

Requires Saxon-PE or Saxon-EE. Available for Java only.

Details

The result of the instruction is a sequence of elements. The local name of the elements will be the value of the row-tag expression if supplied, and they will be in no namespace. In the absence of a row-tag expression, the element name will be derived from the name of the table being queried.

Within these elements, there will be one child element representing each column in the result. If the col-tag expression is present, this will be used to name all the columns; otherwise, column names will be formed from the names returned in the SQL query result (which in turn derive from the column names in the database where available).