Adding XSLT and XQuery Transformations

The next step in building our XML pipeline is to add the XSLT and XQuery transformations generated using XML Publisher. These transformations will render the XML document resulting from the Extract full order information XQuery, myFullOrderSample.xml, as HTML and PDF, respectively.

Of course, if we wanted to, we could have used XQuery to generate the HTML and XSLT to generate the XSL-FO; or we could have used just XQuery or XSLT to generate both document formats. The technology you choose is largely a matter of personal preference, though some are better suited to certain tasks (like data aggregation, HTML formatting, and so on) than others.

Add createReport.xsl

To add createReport.xsl to the XML pipeline:
1. Display the Project window ( View > Project) if it is not already open.
2. Drag createReport.xsl from the pipelines/order folder and drop it on the XML pipeline canvas.

Stylus Studio add an XSLT node to the XML pipeline.

Figure 411. New XSLT Node

The colored input port indicates that this XSLT node already has a default input and value defined for it. We will specify our own input value (the XML document created by the Extract full order information XQuery node).

Tip

 

Stylus Studio uses the file name for the node name when you create the node by dragging and dropping a document on the XML pipeline canvas.

3. Drag a pipe from the output port on the Extract full order information XQuery node to the input port on the new XSLT node.
4. Next, specify a value for the output port ( order.html, for example). See Setting a Value for an Output Port if you need help with this step.

Tip

 

Since we know the XQuery node generates the XML document we require, we can delete the Copy to URL for its output port. Otherwise, output will continue to be written to that URL.

5. Test the XML pipeline by clicking the Execute button ( ).

As currently defined, our XML pipeline should create an HTML report based on the myFullOrderSample.xml document, and this is what appears in the Preview window.

Figure 412. Preview of the XML Pipeline's HTML Output

Tip

 

Click the Preview in Browser button to see the XML pipeline output rendered in HTML.

Add createReport.xquery

All that remains for our XML pipeline definition is to specify the XQuery node that will transform myFullOrderSample.xml into PDF. For this purpose, we will use the createReport.xquery generated by the XML Publisher.

To add createReport.query to the XML pipeline:
1. Display the Project window ( View > Project) if it is not already open.
2. Drag createReport.xquery from the pipelines/order folder and drop it on the XML pipeline canvas.

Stylus Studio may display a warning message, indicating that the processor specified for the createReport.xquery document differs from that specified for the XML pipeline.

3. Click OK to accept the default recommendation. (See Managing Processor Conflicts for more information on this topic.)

Stylus Studio adds a new XQuery and associated XSL-FO node to the XML pipeline.

The XSL-FO node is the result of the post-processing specified for the XQuery - when we generated the XQuery code from XML Publisher, we chose XSL-FO for the Document Type (see Figure 410). Stylus Studio automatically selected the default FO processor, RenderX XEP, to process the FO generated by createReport.xquery.

4. Drag a pipe from the output port on the Extract full order information XQuery node to the input port on the new XQuery node.

Figure 413. New XQuery Node with Automatically Created XSL-FO Node

5. Next, specify a value for the output port ( order.pdf, for example) of the XSL-FO node. See Setting a Value for an Output Port if you need help with this step.
6. Test the XML pipeline one last time by clicking the Execute button ( ).

Stylus Studio reopens the Preview, which displays an execution log for the XML pipeline's operations. New statements appear for the new XQuery and XSL-FO nodes.

Figure 414. Pipeline Execution Log and FO Processor Output

It also reopens the Output window, which shows output from the XSLT processor and the RenderX FO post-processor.

7. Click the second tab in the Preview window to display the PDF document created by the nodes we just added to the XML pipeline.

Figure 415. PDF Created by the XQuery and XSL-FO Nodes

Note

 

If you receive an error during this step, it might mean that Adobe Acrobat Reader was not properly installed on your system. Go to http://www.adobe.com and resinstall Acrobat Reader.

 
Free Stylus Studio XML Training:
W3C Member