MacTransform - XSLT Processor Interface for Macintosh

Download version 2.4.1
Download examples (ZIP format)

This product includes software developed by the Apache Software Foundation
(http://www.apache.org/).

Introduction

In her Visual Quickstart Guide to XML for the World Wide Web (ISBN 0-201-71098-6), Elizabeth Castro remarked that she was looking for an XSLT processor for the Macintosh. I realized that Xalan, written in Java by the Apache Software Foundation, might provide just such a processor.

The most appropriate sample program for the task was SimpleTransform.java in the Xalan distribution. It is designed to run from a command line, but the Macintosh operating system (before OS X, that is) does not provide such a command line. I took the SimpleTransform.java program and added some code to make it into an XSLT processor that would allow easy testing of XML and XSL files.

Requirements

You may download the first two items in the list from Apple Computer's website; the URL is http://devworld.apple.com/java/text/download.html

Although Apple recommends 40MB of memory to run Java, I have tested this software on a Performa 6320CD running Mac OS 8.5 with 32MB of memory and 38MB of virtual memory.

For your convenience, xerces.jar and xalan.jar have been included with this distribution. You may download the latest version of the jar files and the source from the Apache Software Foundation.

The original version worked with an older version of the Xalan and Xerces packages. Thanks to Andrew Steeley, there is now a newer version that works with Xalan version 2.4.1.

Installation

If you don't already have the Macintosh Runtime for Java installed, you'll need to install it according to the instructions along with that package. The SDK (Software Development Kit) is definitely necessary if you want to modify this code. I haven't tested it without the SDK installed, so I highly recommend that you install it as well, again, according to their instructions.

This package contains the following files:

MacTransform.java
The source for the XSLT processor interface
MacTransform.class
The compiled version of MacTransform.java
MacTransform
The double-clickable application that does the work. It's actually a script that serves as a “wrapper” to call the Macintosh Runtime for Java.
MRJApplication.properties
This file contains information that MacTransform needs to find necessary components and redirect standard input. Do not modify this file unless you understand Apple's MRJAppBuilder
xercesImpl.jar
Apache's XML parser (part 1)
xml-apis.jar
Apache's XML parser (part 2)
xalan.jar
Apache's XSLT processor
examples
a directory that contains examples showing how MacTransform can be used. These are in the separate .zip file.

IMPORTANT: Xalan and Xerces don't like blanks in file names. The path to the location where you've installed MacXSLT may not contain any blanks! Thus:

MyDisk:XML-experiments:MacXSLTWorks fine - no blanks
My Disk:XML-experiments:MacXSLTBad - has blanks
MyDisk:XML experiments:MacXSLTBad - has blanks

Using MacTransform

The easiest way to learn how to use MacTransform is to do these examples. The files that the first example uses are simple.xml and simple.xsl in the examples folder. Please take a look at them before you proceed.

  1. Double-click MacTransform. You'll see this prompt:

    Get file names from saved parameter list (ENTER for none) >

  2. We'll talk about these files later; for now, just press ENTER.
  3. MacTransform asks for the name of your XML file. Enter the bold text as shown and press ENTER. You use the Java directory separator ("/") instead of the Macintosh directory separator (":") because this is a Java program.

    XML file name > examples/simple.xml

  4. MacTransform now asks for the name of the XSL file that will process the XML file. Enter the bold text as shown and press ENTER.

    XSL file name > examples/simple.xsl

  5. MacTransform then asks for the name of the output file. If you want your output to go the screen, just press ENTER. In this case, we want the output saved in the file whose name you type:

    Output file name [ENTER alone for screen] > examples/simple.output

  6. MacTransform tells you that it's working, and notifies you when it finishes doing the XSLT processing.

    Transforming examples/simple.xml using examples/simple.xsl with output to examples/simple.output...
    ...finished

  7. Open up simple.output from the examples folder in SimpleText or your favorite text editor to check the result.
  8. MacTransform was designed to make it easy to test, edit, and re-test an XSL file. Rather than having you type all the file names every single time you do a test, the program now asks if you'd like to save all the filenames you typed in a “parameter file.” In this case, yes, you do, so type the filename as shown below, then press ENTER:

    Type name of file to save parameters in, or just press ENTER > examples/simple.parameters

  9. MacTransform asks if you'd like to transform another file (the default is "Yes") In this case, we want to modify the XML file and re-do the transformation. Press ENTER.
  10. Open simple.xml in the examples folder, and change the line reading Simple Document to Simple Modified Document.
  11. You now get the same prompt you got in step 1 above. This time, you want to use the same filenames that you used before, so enter the name as shown below:

    Get file names from saved parameter list (ENTER for none) > examples/simple.parameters

  12. Notice that MacTransform does all the rest of the work for you:

    XML file: examples/simple.xml
    XSL file: examples/simple.xsl
    Output file: examples/simple.output
    Transforming examples/simple.xml using examples/simple.xsl with output to examples/simple.output...
    ...finished
    Type name of file to save parameters in, or just press ENTER >

  13. At this point, the first example is finished. We've already saved the parameter file, so just press ENTER.
  14. At the Transform another file? (Y/N) > , type N and press ENTER.

Inside the Parameter File

In your favorite text editor, open simple.parameters in the example folder (it's the file we created in step 8 above). Here's what it looks like:

	#
	# Generated by MacTransform
	#
	xmlFileName = examples/simple.xml
	xslFileName = examples/simple.xsl
	outputFileName = examples/simple.output

For those of you who are familiar with Java, this is just a standard “properties” file.

Now, open up the catalog.parameters file in the example folder (it has been created for you):

	#
	#	Example parameter file; provides the XML file name, but prompts
	#	you for the XSL and output file names
	#
	xmlFileName = examples/catalog.xml
	xslFileName =
	outputFileName =

MacTransform works as follows: if a file name is not specified in a parameter file, it will prompt you for that filename. This parameter file will let you specify the XSL and output files to use when processing examples/catalog.xml.

Now, let's use this parameter file to do two different conversions on the catalog.xml file. Before proceeding, open catalog.xml in a text editor to see what it looks like.

  1. Double-click MacTransform to start it. Enter the filename as shown below, then press ENTER.

    Get file names from saved parameter list (ENTER for none) > examples/catalog.parameters

  2. Since the parameter file has the XML file name in it, MacTransform shows you that name, and then prompts you for the XSL file name, which you will type as shown below:

    XML file: examples/catalog.xml
    XSL file name > examples/catalog1.xsl

  3. This XSL file happens to produce HTML output, so enter the output file name as shown below when prompted:

    Output file name [ENTER alone for screen] > examples/catalog1.html

  4. MacTransform does its work, and prompts you to save a parameter file. In case you ever want to do this particular transformation again, save the list of filenames in a parameter file as shown below. You can use any name you like; it does not have to end with parameters, as you see below.

    Transforming examples/catalog.xml using examples/catalog1.xsl with output to examples/catalog1.html...
    ...finished
    Type name of file to save parameters in, or just press ENTER > examples/catalog1.params

  5. Before you continue, open catalog1.html in the examples folder with your web browser to see what the transformation has produced.
  6. We want to do another transformation, so answer yes to the prompt:

    Transform another file? (Y/N) > y

  7. Again, you are prompted for a parameter file. Use the same file name that you used in step 1 above.

    Get file names from saved parameter list (ENTER for none) > examples/catalog.parameters

  8. MacTransform again shows you the stored XML file name and prompts you for the XSL file name, which you will type as shown below (note that it's catalog2, not catalog1 this time).

    XML file: examples/catalog.xml
    XSL file name > examples/catalog2.xsl

  9. At the prompt for the output file name, use the corresponding catalog2.html

    Output file name [ENTER alone for screen] > examples/catalog2.html

  10. MacTransform does its work, and prompts you to save a parameter file. In case you ever want to do this second transformation again, save the list of filenames in a parameter file as shown below:

    Transforming examples/catalog.xml using examples/catalog2.xsl with output to examples/catalog2.html...
    ...finished
    Type name of file to save parameters in, or just press ENTER > examples/catalog2.params

  11. Now open catalog2.html in the examples folder with your web browser to see what the transformation has produced.
  12. At the Transform another file? prompt, enter n.

On Your Own

Run MacTransform again. Use examples/catalog.xml as your XML file, examples/catalog3.xsl as the XSL file, and send output to examples/catalog3.rtf. You may use the examples/catalog.parameters file to make your work a little easier. Open examples/catalog3.rtf in your favorite RTF-aware word processor.

Editing the Parameter File

If you edit or construct your own parameter files, and you want the program to prompt you for a filename, make sure you just erase everything after the equal sign. Do not erase the entire line; otherwise MacTransform will tell you that your parameter file isn't valid.

If you want the output to go to the screen, the last line in the file should read:

outputFileName = $CONSOLE