Getting started with the Orangevolt Eclipse XSLT plug-in

Pairing two hot technologies: Eclipse and XSLT

The Orangevolt XSLT plug-in, a successor of the Swing-based ROXES XmlWrite, provides Eclipse with an enhanced XSLT editing environment. The plug-in builds on the existing Eclipse Web Tools Platform (WTP) and introduces new features for XSL and XML. Learn what XSLT can do for you and how easy it is to employ XSLT with the Orangevolt XSLT plug-in.

Share:

Yasmary Hernandez (yasmary@us.ibm.com), Advisory IT Specialist, IBM Japan

Yasmary HernandezYasmary Hernandez is an IT specialist with IBM Software Services for WebSphere focusing on Datapower. She is a graduate of IBM's Extreme Blue internship program.



15 January 2008

Also available in Russian Japanese

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)
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)
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.


Requirements

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.


Installation

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:

  1. Launch your Eclipse environment and choose any workspace.
    Figure 3. Eclipse splash screen
    Eclipse splash screen
  2. Navigate to Help > Software Updates > Find and Install ...
    Figure 4. Help > Software Updates > Find and Install
    Help > Software Updates > Find and Install
  3. The following screen appears:
    Figure 5. Find and Install pop-up screen
    Find and Install pop-up screen
  4. Choose the radio button Search for new features to install and click Next.
    Figure 6. Choose "Search for new features to install"
    Choose Search for new features to install
  5. Click on the New Remote Site... button.
    Figure 7. New Remote Site button
    New Remote Site button
  6. Enter Name: Orangevolt EclipseXSLT and http://eclipsexslt.sourceforge.net/update-site in the URL field.
    Figure 8. New Remote Site details
    New Remote Site details
  7. Click OK.
  8. Check Orangevolt EclipseXSLT and click Finish.
    Figure 9. Select Orangevolt EclipseXSLT
    Select Orangevolt EclipseXSLT
  9. Check Orangevolt EclipseXSLT and click Next.
    Figure 10. Select Orangevolt EclipseXSLT
    Select Orangevolt EclipseXSLT
  10. Accept the license terms and click Next.
    Figure 11. License agreement
    License agreement
  11. Click Finish.
    Figure 12. Installing EclipseXSLT
    Installing EclipseXSLT
  12. The installation will begin.
    Figure 13. Installing EclipseXSLT
    Installing EclipseXSLT
  13. If the following screen appears, click on Install All.
    Figure 14. Installing EclipseXSLT
    Installing EclipseXSLT
  14. After the installation is finished, the following screen will appear. Choose to restart Eclipse.
    Figure 15. Restart Eclipse
    Restart Eclipse
  15. To check whether the installation successfully completed, navigate to Help > Software Updates > Manage Configuration.
    Figure 16. Verify installation
    Verify installation
  16. Make sure you see an entry for Orangevolt EclipseXSLT in the list.
    Figure 17. Verify installation
    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
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
XML design view

Select the Source view. You will notice that the XML is syntax-colored.

Figure 20. XML source view
XML source view

Editor extensions

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
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
Chars to HTML entities

Will result in:

Figure 23. Chars to HTML entities
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
CDATA section

Will result in:

Figure 25. CDATA section
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 element. Type root.
Figure 26. Insert element
Insert element

You should see the following:

Figure 27. Insert element
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
Launching XSLT transformations

Or:

Figure 29. Launching XSLT transformations alternative
Launching XSLT transformations alternative

Double-click on Orangevolt XSLT configuration type to create a new launch configuration.

Figure 30. Launching XSLT transformations
Launching XSLT transformations

Figure 31 shows the XSLT transformations configuration screen.

Figure 31. Launching XSLT transformations
Launching XSLT transformations

Fill in the following fields: Name (TransformerLaunch), Project, Source (data.xml), Stylesheet (transformer.xsl), as shown below, and click Apply.

Figure 32. Launching XSLT transformations
Launching XSLT transformations

Click Run. The console window should display the following.

Figure 33. Launching XSLT transformations
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
Launching XSLT transformations

Refresh your project view to see that the new text file has been added.

Figure 35. Launching XSLT transformations
Launching XSLT transformations

Open the file to view the result of the transformation.

Figure 36. Launching XSLT transformations
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
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
Launching XSLT transformations

The reference documentation for all user-configurable parameters in the DocBook XSL HTML stylesheets is linked in the Resources section.

Post-processing

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
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
Launching XSLT transformations -- Select transfer launch

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
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.


XSLT processors

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
Preferences window

The plug-in provides an area to allow you to customize its preferences. Expand Orangevolt XSLT.

Figure 43. Preferences window
Preferences window

Click on Transformer. You will notice that by default Saxon is selected.

Figure 44. Preferences window: Saxon selected
Preferences window: Saxon selected

You can change this option through the XSLT Processor Configuration drop-down box.

Figure 45. Preferences window: Selecting a processor
Preferences window: Selecting a processor

The plug-in comes with three XSLT processors:

  • Default Transformer — it comes with Eclipse
  • Saxon
  • Xalan

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
Preferences window

Expand Orangevolt to reveal the XPath Navigator and click OK.

Figure 47. Preferences window
Preferences window

You should now see the XPath Navigator view tab.

Figure 48. Preferences window
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
Preferences window

Change around the XPath Expression to yield different results.

Figure 50. Preferences window
Preferences window

Final words

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.


Download

DescriptionNameSize
Sample XML filesos-eclipse-orangevolt.code-samples.zip754B

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Open source on developerWorks


static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Open source
ArticleID=281970
ArticleTitle=Getting started with the Orangevolt Eclipse XSLT plug-in
publish-date=01152008