Oracle8i Application Developer's Guide - XML Release 3 (8.1.7) Part Number A86030-01 |
Library | Service | Contents | Index

Using XML Transviewer Beans, 6 of 15

## Using XSL Transformer Bean (oracle.xml.async API)

The XSL Transformer Bean accepts an XML file and applies the transformation specified by an input XSL stylesheet, to create and output file. It enables you to transform an XML document to almost any text-based format including XML, HTML and DDL, by applying an XSL stylesheet.

When integrated with other beans, XSL Transformer Bean enables an application or user to view the results of transformations immediately.

This bean can also be used as the basis of a server-side application or servlet to render an XML document, such as an XML representation of a query result, into HTML for display in a browser.

The XSL Transformer Bean encapsulates the Java XML Parser XSL-T processing engine with a bean interface and extends its functionality to permit asynchronous transformation.

By registering a listener, your Java application can transform large and successive documents by having the control returned immediately to the caller.

### Many Files to Transform? Use XSL Transformer Bean

XSL transformations can be time consuming. Use XSL Transformer bean in applications that transform large number of files. It can transform multiple files concurrently.

### Need a responsive User Interface? Use XSL Transformer Bean

XSL Transformer Bean can be used for visual applications for a responsive user interface. There are similar issues here as with DOMBuilder bean.

By implementing XSLTransformerListener() method, the caller application can be notified when the transformation is complete. The application is free to perform other tasks in between requesting and receiving the transformation.

### XSL Transviewer Bean Scenario 1: Regenerating HTML Only When Underlying Data Changes

This scenario illustrates one way of applying XSL Transformer Bean.

1. Create a SQL query. Store the selected XML data in a CLOB table.

2. Using the XSL Transfomer Bean, create an XSL stylesheet and interactively apply this to the XML data until you are satisfied by the data presentation. This can be HTML produced by the XSL transformation.

3. Now that you have the desired SQL (data selection) and XSL (data presentation), create a trigger on the table or view used by your SQL query. The trigger can execute a stored procedure. The stored procedure, can for example, do the following:

   - Run the query

   - Apply the stylesheet

   - Store the resulting HTML in a CLOB table.

4. This process can repeat whenever the source data table is updated.

   The HTML stored in the CLOB table always mirrors the last data stored in the tables being queried. A JSP (Java Server Page) can display the HTML.

   In this scenario, multiple end users do not produce multiple data queries that contribute to bigger loads to the database. The HTML is regenerated only when the underlying data changes and only then.

### XSL Transformer Bean Usage

Figure 20-2 illustrates the XSL Transformer Bean usage. For examples of implementing this bean, see "Transviewer Bean Example 1: AsyncTransformSample.java".

#### Figure 20-2 XSL Transformer Bean Usage

1. An XSL stylesheet and XML document input the XSLTransformer using method: `XSLTransfomer.addXSLTransformerListener(XSLTransformerListener).` This adds a listener.

2. The XSLTransfomer.processXSL() method initiates the XSL transformation in the background.

3. Optionally, other work can be assigned to the XSLTransformer Bean. Table 20-2 lists available XSLTransformer Bean methods.

4. When the transformation is complete, an asynchronous call is made and the `XSLTransformerListener.xslTransformerOver()` method is called. This interface must be implemented in order to receive notifications about events during the asynchronous transformation. The class implementing this interface must be added to the XSLTransformer event queue using `addXSLTransformerListener` method.

5. XSLTransformer.getResult() method returns the XML document fragment for the resulting document.

6. It ouputs the XML document fragment.

   ##### Table 20-2 XSLTransformer Bean: Methods

   Method | Description
   --- | ---
   addXSLTransformerErrorListener(XSLTransformerErrorListener) | Adds an error event listener
   addXSLTransformerListener(XSLTransformerListener) | Adds a listener
   getId() | Returns the unique XSLTransformer id
   getResult() | Returns the document fragment for the resulting document.
   processXSL(XSLStylesheet, InputStream, URL) | Initiates XSL Transformation in the background.
   processXSL(XSLStylesheet, Reader, URL) | Initiates XSL Transformation in the background.
   processXSL(XSLStylesheet, URL, URL) | Initiates XSL Transformation in the background.
   processXSL(XSLStylesheet, XMLDocument) | Initiates XSL Transformation in the background.
   processXSL(XSLStylesheet, XMLDocument, OutputStream) | Initiates XSL Transformation in the background.
   removeDOMTransformerErrorListener(XSLTransformerErrorListener) | Removes an error event listener
   removeXSLTransformerListener(XSLTransformerListener) | Removes a listener
   run() |
   setErrorStream(OutputStream) | Sets the error stream used by the XSL processor
   showWarnings(boolean) | Sets the showWarnings flag used by the XSL processor

| Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
Library | Service | Contents | Index