Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Generating Generic XForms for OpenOffice : Page 4

You can generate XForms in OpenOffice from sample input—as long as you're aware of the technique's limitations.

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.

<params> <param name="year">2007</param> <param name="month">01</param> <param name="day">20</param> <param name="addressformat">structuredDK</param> <param name="maincurrency">DKK</param> <param name="linesnumber">5</param> <param name="seteditable">true</param> <param name="filledstyle">default</param> <param name="outputname">Invoice22.xml</param> <param name="outputpath"> D:/projects/tests/work/xforms/OO/ exampleimplementation/output/ </param> <param name="_generic"/> </params>

Example 2: Address Data (see Figure 9)
Figure 9. Address Form: This form replicates the functionality of the form shown in the earlier tutorial "Getting Started with XForms in OpenOffice."
This example uses the element names to give names to input fields (this is of course configurable).

<?xml version="1.0" encoding="utf-8"?> <Address><street/><number/><city/><zone>2400</zone> <country>Denmark</country></Address>

Example 3: UBL Reminder Form (see Figure 10)
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.

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

Bryan Rasmussen has been employed by the Danish Government's Data Standardization Project OIOXML with an overview of Core XML and Web technologies, as well as the Danish subset of UBL. He currently works for Software Innovation, one of the Danish Government authorized distributors of FESD Software.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.