XSLT PipelineXSLT Pipeline
An example of scripting with beanshell
Home > Books > Tutorials and Training Guides > Procedural Scripting > XSLT Pipeline

Rate this page:
Really useful
Satisfactory
Not helpful
Confusing
Incorrect
Unsure
Extra comments:


In this trailmap we'll present a Beanshell script that creates a loosely typed pipeline of XML transforms.

Specification

The script first performs an XSLT transform request to extract Act1 from the King Lear document. It then passes the result to a second XSLT transform request to style the act as HTML. The resulting HTML is returned as the response.

You can execute this script here - compare with the same pipeline implemented in DPML here.

Using the Workbench

  1. The script listed can be found as script.bsh in the base directory of the workbench module. You can try it by clicking http://localhost:8080/workbench/example_beanshell/script.bsh.

Here is the source:


    import org.ten60.netkernel.layer1.nkf.*;
    import org.ten60.netkernel.layer1.representation.*;
    
    /**
    *   Scripted XSLT Pipeline
    */
    void main()
    {
        //Select Act1 from King Lear (.../lear.xml)
        req=context.createSubRequest();
        req.setURI("active:xslt");
        req.addArgument("operand","ffcpl:/xusr/share/doc/docs/xml_technologies/content/lear.xml");
        req.addArgument("operator","ffcpl:/xusr/share/doc/docs/xml_technologies/xslt/act1.xsl");
        result=context.issueSubRequest(req);
        
        //Transform result to XHTML
        req=context.createSubRequest();
        req.setURI("active:xslt");
        req.addArgument("operand",result);
        req.addArgument("operator","ffcpl:/xusr/share/doc/docs/xml_technologies/xslt/act_to_html.xsl");
        result=context.issueSubRequest(req);
        
        //Issue response
        resp=context.createResponseFrom(result);
        resp.setMimeType("text/html");      
        context.setResponse(resp);
    }

Discussion

In the first part of the script we construct an active URI request for the XSLT accessor. Operand and operator are the names of active URI arguments and are set to URIs for the lear.xml and act1.xsl stylesheet (these URIs are NetKernel ffcpl: internal URIs. They source resources provided from the doc-netkernel module which is imported into the workbench's URI address space).

When the sub-request is built it is issued into the workbench's URI address space - NetKernel finds the active:xslt accessor in the xml-ura module and invokes the service which performs the XSLT transform.

The second operation builds another sub-request for the XSLT accessor. This time it applies the act_to_html.xsl transform to the results of the first service request.

Finally the result is returned by setting the response on the context object.

Experiments

  • Try changing the response's mimetype to "text/plain".
  • Try adding a sub-request using the log accessor to examine the resources or intermediate results.
  • Look at the example_beanshell directory for other examples which use local resources in the workbench module.
© 2003-2007, 1060 Research Limited. 1060 registered trademark, NetKernel trademark of 1060 Research Limited.