Contributed by Dmitry Markovski,
updated by Vince Genovese
December 2007
In this tutorial you become acquainted with the XSLT Designer included in NetBeans IDE 6.0. The XSLT Designer is used to develop, deploy and test XSL Transformation Services.
An XSL Transformation Service acts as a web service. It receives messages from an external client, transforms the messages in accordance with an XSL stylesheet, and either sends the messages back to the originator or forwards them to another web service.
In this tutorial you create a simple XSL Transformation Service that receives a message, transforms it, and sends it back to the calling web service.
This tutorial assumes that you have some basic knowledge of, or programming experience with, the NetBeans IDE.
This tutorial assumes that your system meets the requirements specified in the System Requirements section of the NetBeans IDE 6.0 Release Notes.
Before you begin, install the following software on your computer: NetBeans IDE 6.0, with the SOA Pack and GlassFish V2 Application Server, which are required for this tutorial.
This tutorial requires that the GlassFish V2 Application Server, which includes the JBI runtime, has been installed with NetBeans IDE 6.0. Perform the following steps to confirm that GlassFish V2 Application Server is installed with NetBeans IDE 6.0 and that the JBI runtime contains the XSLT Service Engine and Transform Shared Library required for this tutorial:
An XSL Transformation Service is created within an XSLT Module project.
To create a new XSLT Module Project:
Next you create two XML Schema (.xsd) files, a web service description (.wsdl) file and an XSL stylesheet (.xsl) file. To run an XSL Transformation Service, you need at least one XML Schema, one WSDL file and one XSL stylesheet. For the purpose of this tutorial, you create two XML Schemas.
You will create two XML Schemas: HelloXSLTIncoming.xsd and HelloXSLTOutgoing.xsd. You use the former as the basis for the incoming message and the latter as the basis for the outgoing message.
To create the XML Schema for the incoming message:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/HelloXSLTIncoming" xmlns:tns="http://xml.netbeans.org/schema/HelloXSLTIncoming" elementFormDefault="qualified"> <xsd:element name="name" type="xsd:string"></xsd:element> </xsd:schema>
To create the XML Schema for the outgoing message:
<?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/HelloXSLTOutgoing" xmlns:tns="http://xml.netbeans.org/schema/HelloXSLTOutgoing" elementFormDefault="qualified"> <xsd:element name="greeting" type="xsd:string"></xsd:element> </xsd:schema>
You should see two Schema files listed under the Transformation Files node in your HelloXSLTransformation project.
Note: The XML Schema Editor is not the subject of this tutorial. For detailed information on the XML Schema Editor, see Getting Started With XML Schema Tools.
Next you create a web service description file defining the web interface of our XSL Transformation Service.
To create a WSDL file:
You should see the HelloXSLTWSDL.wsdl file listed under the Transformation Files node in your HelloXSLTransformation project.
Note: Creating and Editing WSDL files is not the subject of this tutorial. For detailed information, see Developer Guide to the WSDL Editor.
An XSL stylesheet is an XML file that contains instructions about transforming the incoming message into the outgoing message.
To create an XSL stylesheet:
The HelloXSLTService.xsl node appears under the Transformation Files node in your HelloXSLTransformation project. The HelloXSLTService.xsl file opens in the Design view of the XSL Transformation Editor. The Design view Palette opens on the right.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:ns1="http://xml.netbeans.org/schema/HelloXSLTIncoming" xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing"> <xsl:template match="/"> <xsl:element name="ns:greeting"> <xsl:value-of select="concat('Hello ', /ns1:name)"/> </xsl:element> </xsl:template> </xsl:stylesheet>
An XSLT project is not directly deployable. You must first add an XSLT project as a JBI module to a Composite Application project before you can deploy the Composite Application project. Deploying the project makes the service assembly available to the application server, thus allowing its service units to be run.
To create a Composite Application:
To add a JBI module:
To deploy the HelloXSLTCAP Composite Application:
Testing an XSL Transformation Service means sending a message that the Service is expecting and receiving, in this case, a reply message.
Before we can perform the testing, we must create a test case.
To create a test case:
<hel:name>?string?</hel:name>line to
<hel:name>John Smith</hel:name>The Input.xml file should be:
<soapenv:Envelope xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hel="http://xml.netbeans.org/schema/HelloXSLTIncoming"> <soapenv:Body> <hel:name>John Smith</hel:name> </soapenv:Body> </soapenv:Envelope>
The Output node under the test case node refers to the expected reply message that is used for comparison with the actual reply messages. Before we run the test for the first time, the Output.xml file is empty. We will populate it with the content of the reply message (provided that it is what we expect).
To run the test:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.xmlsoap.org/soap/envelope/ http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <ns:greeting xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing">Hello John Smith</ns:greeting> </SOAP-ENV:Body> </SOAP-ENV:Envelope>Notice the line
<ns:greeting xmlns:ns="http://xml.netbeans.org/schema/HelloXSLTOutgoing">Hello John Smith</ns:greeting>The XSL Transformation Service received the name, concatenated it with the string 'Hello' and sent the reply message.
Congratulations! You have successfully created, deployed and tested an XSL Transformation Service.
Now that you have successfully created the Request-Reply XSL Transformation Service, continue with the Service Bridge type.