If you are an experienced XSLT programmer who is not familiar with Eclipse, this article is intended to show you how easy it is to use Eclipse. If you are an experienced Eclipse user wondering what XSLT is all about, this article will introduce you to its wonders.
We start with a brief overview of XSLT. Then we go into specifics of using the Eclipse plug-in, including installing and using most of its functions.
What is XSLT?
Let's start with the basics: XML. Nowadays, it is hard not to go on the Web and hear about it. XML plays an important role as a data facilitator across myriad systems. The very fact that XML's extreme flexibility allows for the creation of customized vocabularies presents the need to be able to transform from one vocabulary to the next.
Enter XSLT. Extensible Stylesheet Language Transformations (XSLT) enables interoperability. In other words, its primary goal is to take an XML-based markup language as input and transform it either into another markup language or into plain text.
Suppose you want to create a simple movie rental Web site. All your users' preferences, such as favorite movie genre, are stored in an XML file (see Figure 1). How would you utilize this information for performing queries, for instance? You can use an XSLT stylesheet to transform the user preferences into a set of database instructions (see Figure 2). These database instructions can then retrieve information like how many movies are in your inventory that relate to a specific user's favorite movie genre. Furthermore, you can even use another XSLT stylesheet to process the information retrieved from the database query and transform it into an HTML page to present to a specific user.
The following code samples will be used in this article to illustrate the plug-in's functionality. You can download them in the Download section.
Figure 1. Example XML file containing user preferences for fictional movie rental Web site (data.xml)
Figure 2. Example XSLT stylesheet which transforms XML file into a database query (transformer.xsl)
Overview of the Orangevolt EclipseXSLT plug-in
The Orangevolt XSLT plug-in, successor of the Java™ Swing-based ROXES XmlWrite, provides Eclipse with an enhanced XSLT editing environment. The plug-in builds upon the existing Eclipse Web Tools Platform (WTP) and introduces new features for XSL and XML (described later). These features include easy-to-use editor extensions, XSLT-specific launch configurations, syntax-colored XSLT process output, XPath navigator view, among others. In addition, one of the most interesting features of the plug-in is its ability to add and configure XSLT processors. The plug-in includes XSLT processors, such as Xalan and Saxon. Another exciting aspect of the plug-in is that it is being considered to be incorporated into the next major WTP release.
The plug-in requires that the following is installed (see Resources):
- Eclipse IDE V3.3 or later
- Java 2 Platform Standard Edition V1.5 or later
- Eclipse Web Tools Platform (WTP) V2.0.1 or later; you can download the all-in-one
package or download the following prerequisites:
- Eclipse Modeling Framework SDK V2.3.1 or later
- Java EMF Model SDK V1.2.4 or later
- Graphical Editing Framework V3.3.1 or later
You can update your versions by using the Eclipse Europa update site at http://download.eclipse.org/releases/europa/site.xml. If you are unsure as to how to use the update site link, follow the steps below.
To manually install the plug-in, download it. Once downloaded, extract the folders into your eclipse directory. Follow these easy steps to install the plug-in through the update site:
- Launch your Eclipse environment and choose any workspace.
Figure 3. Eclipse splash screen
- Navigate to Help > Software Updates > Find and Install ...
Figure 4. Help > Software Updates > Find and Install
- The following screen appears:
Figure 5. Find and Install pop-up screen
- Choose the radio button Search for new features to install and click
Figure 6. Choose "Search for new features to install"
- Click on the New Remote Site... button.
Figure 7. New Remote Site button
- Enter Name: Orangevolt EclipseXSLT and
http://eclipsexslt.sourceforge.net/update-site in the URL field.
Figure 8. New Remote Site details
- Click OK.
- Check Orangevolt EclipseXSLT and click Finish.
Figure 9. Select Orangevolt EclipseXSLT
- Check Orangevolt EclipseXSLT and click Next.
Figure 10. Select Orangevolt EclipseXSLT
- Accept the license terms and click Next.
Figure 11. License agreement
- Click Finish.
Figure 12. Installing EclipseXSLT
- The installation will begin.
Figure 13. Installing EclipseXSLT
- If the following screen appears, click on Install All.
Figure 14. Installing EclipseXSLT
- After the installation is finished, the following screen will appear. Choose to
Figure 15. Restart Eclipse
- To check whether the installation successfully completed, navigate to Help >
Software Updates > Manage Configuration.
Figure 16. Verify installation
- Make sure you see an entry for Orangevolt EclipseXSLT in the list.
Figure 17. Verify installation
Basic plug-in functionality
Now that you have installed the plug-in, we can take a deeper look into all of its features.
Create a new project and add data.xml, located in the Download section. When you open the file, you should notice that the plug-in has two views: Design and Source.
Figure 18. XML file view
Expand all the elements under the Design view. You should see a tree structure view of all the XML elements, along with their values.
Figure 19. XML design view
Select the Source view. You will notice that the XML is syntax-colored.
Figure 20. XML source view
The XML editor builds upon the existing Eclipse WTP editor and adds new features. To view these extra features, navigate to the data.xml file Source view. Right-click on any whitespace to bring up a context menu. The new features are highlighted in red below.
Figure 21. XML source context view
Each feature is described below.
- Insert date
- Will insert the current date where desired. Format: YYYY-MM-DD
- Chars to HTML entities
- Will convert the highlighted text into HTML entities. For example, converting the following:
Figure 22. Chars to HTML entities
Will result in:
Figure 23. Chars to HTML entities
- HTML Entities to Chars
- Is the reverse of "Chars to HTML Entities"
- CDATA section
- Encapsulates the selected value as CDATA. For example, the following:
Figure 24. CDATA section
Will result in:
Figure 25. CDATA section
- Insert element
- The highlighted text will be encapsulated with the element you are adding. For
example, select all of the text in data.xml, right-click it and select insert
Figure 26. Insert element
You should see the following:
Figure 27. Insert element
- Show in navigation
- Right-click any area in a file and select Show in Navigation. The Package Explorer view will highlight which file is being referenced.
Launching XSLT transformations
You can invoke an XSLT transformation by creating an Eclipse launch configuration. This is simply a configurable mechanism that allows you to specify a name, project, source XML file, stylesheet, XSLT stylesheet parameters, XSLT post-processing preferences, and VM arguments.
To create an Eclipse launch configuration specific to this plug-in, navigate to Run > Run... or Run > Open Run Dialog....
Figure 28. Launching XSLT transformations
Figure 29. Launching XSLT transformations alternative
Double-click on Orangevolt XSLT configuration type to create a new launch configuration.
Figure 30. Launching XSLT transformations
Figure 31 shows the XSLT transformations configuration screen.
Figure 31. Launching XSLT transformations
Fill in the following fields: Name (
Project, Source (data.xml), Stylesheet (transformer.xsl), as shown below, and click
Figure 32. Launching XSLT transformations
Click Run. The console window should display the following.
Figure 33. Launching XSLT transformations
If you scroll to the right-most edge of the console window, you will notice that a text file was created.
Figure 34. Launching XSLT transformations
Refresh your project view to see that the new text file has been added.
Figure 35. Launching XSLT transformations
Open the file to view the result of the transformation.
Figure 36. Launching XSLT transformations
Notice how the database query now includes the value Comedy. Another way to run this transformation is to click on the Run icon and select TransformerLaunch.
Figure 37. Launching XSLT transformations -- Select TransformerLaunch
You can configure other properties, such as stylesheet parameters and post-processing options described in the next sections.
XSLT stylesheet parameters
You can add stylesheet parameters needed during the transformation.
Figure 38. Launching XSLT transformations
The reference documentation for all user-configurable parameters in the DocBook XSL HTML stylesheets is linked in the Resources section.
A common practice is to execute an Apache Ant build file when the transformation has completed. This is helpful, for example, if you wanted to convert the result into a PDF (code sample below).
Figure 39. Example Apache Ant built file that will convert an XML-FO file into a PDF
To invoke your Apache Ant build file, open the TransformerLaunch configuration window. Click on XSLT Post Processing. Choose your Ant file from the drop-down box.
Figure 40. Example Apache Ant built file that will convert an XML-FO file into a pdf
Plug-in console window
The Orangevolt EclipseXSLT console window extends the default console view that comes with Eclipse by adding a coloring scheme for the process output. For example, errors and warnings are in red.
Figure 41. Launching XSLT transformations: Errors are in red
Also, the plug-in provides output hyperlinking, which allows you to jump to the specific line where the error occurred by simply clicking on the error.
An XSLT processor is simply a software component that invokes an XSLT stylesheet on an XML document, producing output (types: XML, HTML, or text).
There are lots of XSLT processors available. Currently, the three major processors are:
- MSXML, authored by Microsoft®
- Saxon, authored by Michael Kay
- Xalan, authored by the Apache Project
Orangevolt EclipseXSLT allows you to choose which processor you prefer using, as well as add your own.
Choosing a new XSLT processor
Navigate to Window > Preferences.
Figure 42. Preferences window
The plug-in provides an area to allow you to customize its preferences. Expand Orangevolt XSLT.
Figure 43. Preferences window
Click on Transformer. You will notice that by default Saxon is selected.
Figure 44. Preferences window: Saxon selected
You can change this option through the XSLT Processor Configuration drop-down box.
Figure 45. Preferences window: Selecting a processor
The plug-in comes with three XSLT processors:
- Default Transformer — it comes with Eclipse
Adding a new XSLT processor
The plug-in provides an Eclipse extension point for adding your own XSLT processor. For a quick tutorial, visit SourceForge.
Using the XPath Navigator
The XPath Navigator view is a nice feature. It is useful for creating an XPath expression from a specific source XML file. The plug-in will execute the XPath query against the DOM representation of the XML file.
Navigate to Window > Show View > Other....
Figure 46. Preferences window
Expand Orangevolt to reveal the XPath Navigator and click OK.
Figure 47. Preferences window
You should now see the XPath Navigator view tab.
Figure 48. Preferences window
Select data.xml from the XML Source Document drop-down box. Type
//customer in the XPath Expression text box. Click the Run
icon within the Navigator to reveal the result.
Figure 49. Preferences window
Change around the XPath Expression to yield different results.
Figure 50. Preferences window
By now you've seen, if you hadn't already, the immense customizability of Eclipse. Keep an eye out, as the technology you are working with might have an Eclipse plug-in available for it. In the case of the XSLT technology, Orangevolt EclipseXSLT proves to be a capable addition to any developer's toolbox. Be sure to check out the Resources for more learning materials.
|Sample XML files||os-eclipse-orangevolt.code-samples.zip||754B|
- "What kind of language is XSLT?" is a guide to understanding and learning XSLT.
- "Why I teach Eclipse" is a discussion of Eclipse technology.
- Check out the XSL Transformations (XSLT) Version 1.0 recommendation for the W3C specification for XSLT language syntax and the XML Path Language (XPath) Version 1.0 recommendation for the W3C specification for XPath expression syntax.
- Reference documentation for all user-configurable parameters in the DocBook XSL HTML stylesheets.
- Learn about Saxon, Xalan, and Apache Ant.
- The XSLT Project contains the functionality provided by Orangevolt's plug-in and includes an XSL debugger, as-you-type validation, and XPath content-assist. XSL Tools is an Eclipse WTP Incubator project.
- Check out the "Recommended Eclipse reading list."
- Browse all the Eclipse content on developerWorks.
- New to Eclipse? Read the developerWorks article "Get started with Eclipse Platform" to learn its origin and architecture, and how to extend Eclipse with plug-ins.
- Expand your Eclipse skills by checking out IBM developerWorks' Eclipse project resources.
- To listen to interesting interviews and discussions for software developers, check out developerWorks podcasts.
- For an introduction to the Eclipse platform, see "Getting started with the Eclipse Platform."
- Stay current with developerWorks' Technical events and webcasts.
- Watch and learn about IBM and open source technologies and product functions with the no-cost developerWorks On demand demos.
- Check out upcoming conferences, trade shows, webcasts, and other Events around the world that are of interest to IBM open source developers.
- Visit the developerWorks Open source zone for extensive how-to information, tools, and project updates to help you develop with open source technologies and use them with IBM's products.
Get products and technologies
- Download Orangevolt EclipseXSLT at SourceForge.net.
- Download the latest Eclipse IDE.
- Download the latest Java JDK from Sun Microsystems.
- Download the latest Eclipse WTP.
- Download the latest Eclipse Modeling Framework (EMF)— prerequisite for WTP.
- Download the latest Graphical Editing Framework (GEF)— prerequisite for WTP.
- Check out the latest Eclipse technology downloads at IBM alphaWorks.
- Download Eclipse Platform and other projects from the Eclipse Foundation.
- Download IBM product evaluation versions, and get your hands on application development tools and middleware products from DB2®, Lotus®, Rational®, Tivoli®, and WebSphere®.
- Innovate your next open source development project with IBM trial software, available for download or on DVD.
- Check out the Orangevolt EclipseXSLT forum.
- The Eclipse Platform newsgroups should be your first stop to discuss questions regarding Eclipse. (Selecting this will launch your default Usenet news reader application and open eclipse.platform.)
- The Eclipse newsgroups has many resources for people interested in using and extending Eclipse.
- Participate in developerWorks blogs and get involved in the developerWorks community.