Use WDSc to Develop XSL Transformations
August 1, 2007 Ted Holt
I use WebSphere Development Studio client (WDSc) often for editing RPG, CL, command, and DDS source code. I was happy to learn recently that WDSc also works well for the development of XSL transformations. I don’t consider myself a pro at it, but I’m finding WDSc so helpful with my XML projects that I wanted to go ahead and share something of what I’ve learned so far. First, I need to mention that I am currently using WDSc 6.0.1. I have tried XSL transformations under the full product and WDSc Lite, and both have worked well for me so far. Since I don’t have WDSc 7 yet, I don’t know if the following instructions will work for that version or not. Let’s say you want to develop an XSL transformation. That is, you want to use XSL to convert an XML file to a different format, or to a different XML format. You’ll need to use the Resource perspective in WDSc. (According to the help text, other perspectives are acceptable, too, but I don’t know which ones they are.) There are at least two ways to switch to the Resource perspective. Here’s one of them:
Now that you’re in the Resource perspective, you need a working set in order to group resources. My setup already had a working group called xcv. I’ve been using it. If you want to create your own working group, follow these steps:
Now you need to activate your working set in the Navigator pane. On the Navigator pane, just below the tab, is a row of icons. The last one is an arrow head that points down.
This screen shot may help a little: The working set is now open in the Navigator panel, but it’s empty. You need a project.
You have a working set and a project. You need to tie the two together.
Your project should now show in the Navigator pane. Now you need to put two files–an XML file and an XSL file–into the project.
You will be asked to create a new file resource. You’ll see a list of projects.
The XML file is now open in the editor. It’s blank. Key in some XML data. Feel free to use the following: <?xml version="1.0" encoding="UTF-8" ?> <library> <book> <title>Anna Karenina</title> <author>Leo Tolstoy</author> </book> <book> <title>The Count of Monte Cristo</title> <author>Alexandre Dumas</author> </book> <book> <title>Horticulture for Geniuses</title> <author>Phil O. Dendron and Chris Anne Themumm</author> </book> </library> Use your favorite method to save the file. Control-S works well. You can also use the File menu or click on the diskette icon of the toolbar. You have an XML file. Now you need an XSL file.
I suggest you give the XML and XSL files the same base name. If you called the XML file library.xml, then call the XSL file library.xsl. The XSL file is open in the editor. (The XML file is still open as well.) Key the XSL data. (Here’s some you can use.) <?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" > <xsl:template match="library"> My Library <xsl:apply-templates /> </xsl:template> <xsl:template match="book"> <xsl:value-of select="title" /> was written by <xsl:value-of select="author" />. </xsl:template> </xsl:stylesheet> Save the file using your method of choice. At this point, you have two files open in the editor, and your project shows in the Navigator pane. This is how the screen looks on my system: Click on the XML and XSL files in the Navigation pane to select them. You’ll need to hold down the control key while clicking the second of the files in order to select two files at once. With both files selected, right-click on either file, select Run, then XSL Transformation. If there are errors, WDSc responds with a message in red in the Console pane, as below: But if all is OK, you’ll see a new XML file open in the editor, as below: This is the output of the transformation. If I haven’t omitted anything, you should be on your way to developing your own XSL transformations under WDSc.
|