The Translator Xbean


The translator is a source and a sink Xbean that translates an XML document from one arbitrary DTD to another. The translator depends on an XSLT engine to accomplish the translation. It uses the javax.xml.transform interface. As such, it can, in theory, use any XSLT engine supporting that interface.

For those who do not want to write an XSL file, the translator includes a graphical Java Bean customizer for easily specifying the translation. The customizer generates the XSL file based on point and click mappings. See below for more details about using the customizer.

Bean Properties

DOMListener As with all source Xbeans, the DOMListener property is the next Xbean in the channel. The DOMListener receives the DOM produced by this Xbean.


The XSL file that specifies how the incoming document should be translated into the outgoing document. You can set this property directly or you can use the customizer to generate the XSL file and set this property. 


The translator Xbean is in the org.xbeans.translator package. The package can be imported into Java source code as follows:

import org.xbeans.translator.TranslatorBean;

Creating a translator Xbean is accomplished by instantiating the class:

TranslatorBean translator = new TranslatorBean();

After creating the translator Xbean, you need to get a DOM document by registering the translator with the previous Xbean in the channel.


Next, you need to decide if the translator is also to be a source Xbean, that is if the DOM document that it translates is to be passed on to the next Xbean . To pass the document on to the next Xbean, you simply register the next Xbean to be the DOM Listener.


Note that if you are using a Java Bean design tool found in many Java Integrated Development Environments, the above calls are generated automatically when you drag and drop a translator Xbean into your application and set the properties with a property editor.

Finally, you must set the translationFile property:


Again, if you are using a Java Bean design tool, this call is automatically generated for you when you set the property in the property editor or if you use the translator's customizer to automatically generate the xsl file.

Using the Customizer

Rather than writing an XSL file yourself, the translator's customizer will generate one for you. You simply invoke the customizer from the Java Bean design tool, specify the transformation you want and then save the translation in an XSL file. The translationFile property is then automatically updated for you.

The following screen shots were taken from JBuilder. Other Java Design Tools will have analogous functionality.

To invoke the customizer, you simply right click the translator bean and select the customizer menu item.

This invokes the translator's customizer. The next screen you should see is an empty customizer:

The customizer has source and target panels that show the source and target DTDs and allow you to specify assignments from the source document to the target document.

To load the target panel you can either click the word "Target" or use the Translation->Set Target DTD" menu item. Analogous actions allow you to load the source panel. After loading the source and target DTDs you should see:

ln order to specify assignments from your source document to your target document, you must indicate which of the elements are the root elements. Do this by selecting the element, right clicking and selecting the "Set Target Root Element".

Do the same for the source DTD. You should then see:

You are now ready to specify assignments from your source document to your target document.

Simply navigate both DTDs and select nodes. When you have a valid assignment, the "Add" button will be enabled. Pressing the "Add" button will add the assignment to the list of assignments.

If you want to see the generated XSL, you can use the Translation->View XSL menu item.

Finally, when you are done, you need to save the translation. Do that by using the Translation->Save menu item.

When you save the generated XSL file, note that the translator's translationFile property will be automatically updated with the name of the XSL file you have saved.

Finally, quit the customizer by selecting the OK button.

Note that if you want to save your work in the customizer, so that you can return to it later, you should invoke the Project->Save menu item.

Source files

The source files for the translator can be found in the following directories: