Transforming XSQL Page Results with XSLT

Since the data page that results from executing the queries in your XSQL page template is an XML document, and since XSLT offers a robust, declarative mechanism for transforming XML documents into anything else, we can put the two together to achieve a highly effective one-two punch:

  1. The XSQL page assembles XML information relevant to the task at hand.

  2. The XSLT stylesheet transforms it into an appropriate format for delivery.

We’ll look at a few examples in this section that illustrate this approach.

Associating a Stylesheet with an XSQL Page

To associate an XSLT stylesheet with an XSQL page, we use the standard technique prescribed by the W3C (see http://www.w3.org/TR/xml-stylesheet), the <?xml-stylesheet?> processing instruction. It goes after the <?xml version="1.0"?> declaration and before the document element in your XSQL page. It must include as attributes two key pieces of information required to identify the stylesheet:

  • An href attribute that describes the absolute or relative location of the desired stylesheet

  • A type= "text/xsl" attribute that indicates the type of stylesheet in use

Including an <?xml-stylesheet?> instruction of type "text/xsl" in your XSQL page causes the XML document obtained by expanding the XSQL page’s <xsql:query> tags to be transformed by the indicated stylesheet in the server before returning the results to the requester. Only an <?xml-stylesheet?> instruction with an attribute of type="text/xsl" will be considered ...

Get Building Oracle XML Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.