Importing the Filter and Generating a Package
Making a new filter in OpenOffice using XSLT can be somewhat tedious. The process consists of associating the filter with a file extension and a filter name, choosing either an import or export XSLT or both, and then generating a package for your filter.
Step 1—Turn the XSLT into a Filter.
Launch OpenOffice and choose the menu Tools (XML Filter Settings as shown in Figure 4
). You'll see the XML Filter Settings dialog shown in Figure 5
, which lists your saved filter settings.
|Figure 4. Creating a Filter: To associate OpenOffice with XML files that you want to open as XForms you need to turn the GenericFilter.xsl stylesheet into an OpenOffice XML Filter.||
|Figure 5. XML Filter Settings Dialog: Saved filters appear in the XML Filter Settings dialogue. ||
|Figure 6. Defining a New Filter: Fill in the appropriate values in both the General and Transformation tabs.|
You can create a new filter, edit an existing filter, delete filters, or save filters as a package. You can delete a filter by clicking the Delete button. Close and then reopen the Filter dialog to ensure the filter was deleted. If your new filters don't appear here something is wrong.
In this case, click the New button to create a new filter.
You enter the data for your new filter in a tabbed popup window with two panels, the first panel is named General and controls such things as the Filter name, the second is Transformation where you will put in values for the XSLT. This form is shown in Figure 6
Change the Filter Name to something descriptive, such as "Generic XForms." Change the Application field to odt
, and change the file type to XFORMS-INPUT
, but leave the file extension set to xml
. The General tab should now look like Figure 7
|Figure 7. Filter Settings Example: Here's how the first panel of your new filter's settings should look if you followed the suggestions in this article.|
Next, switch to the Transformation panel. This panel has only one input field of interest, a field which has the label 'XSLT for Import." Browse to the GenericFilter.xsl
file and select it. When the path shows up in the input field, click OK. The dialog will close. You should now see the new filter in the XML Filter window.
At this point you should be able to open any XML document that is not a mixed content document and edit it as an XForm.
The following examples show the forms generated for three separate XML examples, along with the XML input data that generated each form.
Example 1: Params File (see Figure 8)
|Figure 8. Params File: The params file is an extremely flat file structure in which there are only two types of inputs: the param element and its name attribute.|
The XML input for the preceding XForm shows how attributes in the default implementation are implemented following the element inputs. A typical configuration would be to generate a table and to put the element in one table column, and the attributes in another one.
Example 2: Address Data (see Figure 9)
This example uses the element names to give names to input fields (this is of course configurable).
Example 3: UBL Reminder Form (see Figure 10)
<?xml version="1.0" encoding="utf-8"?>
|Figure 10. Reminder Document: This example XForm was generated from a larger document—a UBL Reminder document. The full form is not shown as it covers several pages.|
shows the full form code.
To sum up, this article demonstrated a method to generically transform XML input formats to generate XForms that will run in OpenOffice so users can edit the XML input values. The XSLT used in the article is sufficiently configurable that you can maintain, extend, and reuse it relatively easily without breaking functionality.