Chapter 8: XSLT Examples for FileMaker Pro XML

Chapter 8: XSLT Examples for FileMaker Pro XML

This chapter will use all of the information presented in the previous chapters to show you how to use XSL stylesheets with FileMaker Pro 6 import, export, and XML web publishing. We will begin with some basic stylesheets and progress to more complex stylesheets.

8.1 Creating Databases from XML Sources

8.11 Create a Database with FMPXMLRESULT

This example shows how an XML document formatted in the FMPXMLRESULT grammar can be used to create a new FileMaker Pro 6 database.

  1. Launch FileMaker Pro 6 and export XML with FMPXMLRESULT grammar from any of your databases or use the Export.fp5 database found in Chapter 2. Include a variety of field types, such as text, number, and date, and save the document as Export0811.xml.

  2. If you specify Format output using current layout and have the field on the layout formatted to display two decimal places, your number fields will retain two decimal places in, for example, the data exported. If you prefer, perform the export again and use the field formats on your layout.

  3. Close all databases but leave FileMaker Pro running simply to see the new database that you will create, rather than using the XML in an import to an existing database.

  4. From the menu, choose File, Open and you will be presented with the Open File dialog. Change the Show pop-up to XML Source if it is not already selected.

  5. The Specify XML and XSL Options dialog will appear. Choose the File radio button under Specify XML Source. If File is not already selected, you will get the Open dialog. If File is already selected, click the Specify button to get the Open dialog.

  6. Navigate to the XML document you just created, select it, and click the Open button.

  7. Now that you have selected the XML file to use as a source, click the OK button in the Specify XML and XSL Options dialog. You will get another dialog asking you to name the new database file. Call it Export0811.fp5 and click the Save button.

  8. The fields are created and the data is imported into the new database.

  9. Take a look at the XML document Export0811.xml, and then compare its <METADATA> section and the Define Fields dialog in the newly created database Export0811.fp5. If you have a number field (TYPE="NUMBER" in the XML), that type is used to create the field. The other field types are determined by the TYPE attribute in the FIELD element.

Challenge: Export other field types (summary, calculated, and global) and look at the value of the TYPE attribute and the field type if you create a new database with your XML export.

8.12 Create a Database with FMPDSORESULT

An XML document that uses FMPDSORESULT grammar has to be transformed into FMPXMLRESULT grammar before it can be used to create a database. An XSL stylesheet is used to make the transformation. The elements in the XML will become the field names in the new database. The next section will demonstrate transforming FMPDSORESULT into FMPXMLRESULT. Since many XML documents have a similar structure (element names will become the field names), these examples will be helpful for some of the other examples in this chapter.