sql:query

sql:query performs a query, and writes the results of the query to the result tree, using elements to represent the rows and columns. 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. The attributes are as follows:

connection

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

table

The table to be queried (the contents of the FROM clause of the select statement). This is mandatory, the value is an attribute value template.

column

The columns to be retrieved (the contents of the SELECT clause of the select statement). May be "*" to retrieve all columns. This is mandatory: the value is an attribute value template.

where

The conditions to be applied (the contents of the WHERE clause of the select statement). This is optional: if present the value is an attribute value template.

row-tag

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

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

Allowed values are "yes" or "no", 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.