7.1 XSL is XML

7.1 XSL is XML

XSL documents are written with rules and recommendations that follow the structure of well-formed and valid XML documents. If you open an XSL document with a text editor, you will see the familiar tree-like structure of XML with start, end, and empty markup tags. The transformations that are performed by the Extensible Stylesheet Language can be used to create XML documents, as well as other document formats.

The XSL document begins with the XML prolog:

<?xml version="1.0" ?>

The root element for the XSL document is <xsl:stylesheet>. This root element has the attribute "xmlns," for XML namespace. The value for the xmlns attribute has caused some controversy. An early adoption of XSL by Microsoft for use in the Internet Explorer browser uses the xmlns "http://www.w3.org/TR/WD-xsl." The current standard set by the World Wide Web Consortium uses the namespace "http://www.w3.org/1999/XSL/Transform." The version that you use will depend on the browser that is used to display the stylesheet. The examples in this chapter will use all the namespace declarations and qualify the browser type and version used with each. For XML import and export in FileMaker Pro, use the most current namespace declaration, "http://www.w3.org/1999/XSL/Transform."

<!-- current namespace declaration -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- old namespace declaration -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">

The element xsl:stylesheet can have the attributes xmlns, id, extension-element-prefixes, exclude-result-prefixes, and version. Version is the only required attribute. An alternate root element name, xsl:transform, performs the same as xsl:stylesheet.

<xsl:stylesheet version="1.0"
... or ... <xsl:transform version="1.0"

The attribute exclude-result-prefixes can list the elements that should not copy over the namespace prefix from the source XML to the resulting XML. You may use this when you are transforming the FMPXMLRESULT and simply changing the field names. An example showing the usage of this attribute is found in Listing 2.12 when the xsl:copy-of element is used.

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
  Transform" xmlns:fmp="http://www.filemaker.com/fmpxmlresult"

7.11 Namespace Declarations

The namespace value is written as a Uniform Resource Identifier (URI). The namespace declaration looks like a hypertext link to a valid location on the Internet. The URI does not always go to a location, but it does identify a unique name. Some namespace URIs may be valid hypertext references with the XML Schema or DTD documents at that location. The document "Namespaces in XML," found at http://www.w3.org/TR/REC-xml-names, defines the namespaces. The namespace declaration serves as a reference to the elements and attributes used in the document and binds them with the unique reference.

Elements without namespace prefixes may use the namespace of the parent elements, including the root element. Browsers may accept the HTML markup without a namespace declaration and use the default unique identifier for HTML. For example, the HTML document may contain HTML markup without specifying the namespace. By declaring the namespace at the beginning of the document a shortcut to the resource can be used or the default can be assumed, as in Listing 7.2.

Listing 7.1: HTML elements with namespaces
Start example
<!-- HTML elements with namespace -->
<html:html xmlns:html="http://www.w3.org/TR/xhmtl1/strict">
<html:title>Document Name</html:title>
      </html:head> <html:body>
            <!-- content here -->
End example
Listing 7.2: HTML elements without namespaces
Start example
<!-- HTML elements with default namespace -->
<html xmlns:html="http://www.w3.org/TR/xhmtl1/strict">
<title>Document Name</title>
            <!-- content here -->
End example

The above examples are greatly exaggerated but serve to introduce the concept of namespace declarations to identify the elements in an XML document. The namespace declarations for multiple sources provide a means to associate the elements with the correct source. The example in Listing 7.3 shows the declarations and associations for multiple XML element sources.

Listing 7.3: Namespace usage
Start example
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
<xsl:template match="/">
            <html:p>This is from a FileMaker Pro result:
            <xsl:value-of select="//fm:ROW/fm:COL/fm:DATA" />
                This is from an SQL query: <xsl:value-of
                  select="//sql:ROW/sql:COL/sql:DATA" />
End example

The multiple declarations allow us to use the same element names from multiple sources. The "//ROW/COL/DATA" elements in Listing 7.3 could easily confuse the processor if we had not appended the prefix to them. The use of the prefix binds the element to a unique namespace in the XML document.

The namespace is copied to the resulting document except in the following circumstances:

  • The xsl: namespace in the xsl:stylesheet element is never copied.

  • Namespace prefixes listed with the xsl:stylesheet attributes extension-element-prefixes and extension-result-prefixes are not copied to the result document.

7.12 Namespaces in FileMaker Pro 6

The XML that results from a query to a web-published FileMaker Pro database with the -format parameter includes the namespace declaration. Each of the three schema types has a different namespace:

  • -format=-fmp_xml&-view

    <FMPXMLLAYOUT xmlns="http://www.filemaker.com/ fmpxmllayout">

  • -format=-fmp_xml&-find

    <FMPXMLRESULT xmlns="http://www.filemaker.com/ fmpxmlresult">

  • -format=-fmp_dso&-find

    <FMPDSORESULT xmlns="http://www.filemaker.com/ fmpdsoresult">

Database Design Reports and Namespaces

The document Default.xsl is included with FileMaker Pro Developer 5.5 for displaying the XML produced by the Database Design Report. This document uses the older namespace version xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl". You may change the declaration to the newer version if you have a browser that is compliant with the World Wide Web Consortium recommendations. The XSL and XPath standards may be different when you use the older namespace, so merely changing the namespace declaration may not render the report correctly in the browser. Differences in XSL namespace and XPath usage will be noted in this chapter.

Example XML Files in FileMaker Pro

The example files, which are included with FileMaker Pro Developer 5.0 and FileMaker Pro Unlimited 6, use the older namespace in the people_form.xsl:

<?xml version="1.0"?>

The examples also use JavaScript and the Document Object Model (DOM) to present the XML published by Web Companion. Only the Windows version of Internet Explorer 5 or greater will work properly with the examples. The JavaScript calls ActiveX, which only works on the Windows operating system.

var xmlDocument = new ActiveXObject("Microsoft.XMLDOM");

You may get unpredictable results using these examples.

7.13 Stylesheet Instruction in XML Documents

The XML information for a database file in the Database Design Report contains the prolog <?xml version="1.0"?>. The second line in the report is a processing instruction specifying the stylesheet to be used with the document:

<?xml-stylesheet type="text/xsl" href="Default.xsl"?>

The processing instruction xml-stylesheet has six attributes. The type attribute is required. If the stylesheet is XSL, the type attribute will have the value "text/xsl". The Cascading Style Sheet has a type attribute value of "text/css". The href attribute is also required in the xml-stylesheet processing instruction. The href attribute may be a relative or absolute URI path to the stylesheet document. Just like the hyperlink reference in HTML, this URI is not a namespace declaration, but the real location to the document. The href can be a fragment path, thus allowing the stylesheet to be a part of the XML document:

Listing 7.4: XML with embedded XSL
Start example
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="#RefName" ?>
     <xsl:stylesheet id="RefName" version="1.0"
          <xsl:template match="/"
                <xsl:apply-templates />
          <xsl:template match="def">
                     <xsl:value-of select="." />
     <def>some content</def>
End example

The stylesheet processing instruction has optional attributes that are not used by FileMaker Pro. The title, media, charset, and alternate attributes may be used with the XSL processing instruction in other applications.

7.14 Stylesheet Processing Instruction from HTTP Requests

When you issue an XML request to FileMaker Pro Web Companion, you can specify a stylesheet to be used with the result. There are two parameters used to bind the result to the stylesheet. These parameters are -styletype and -stylehref and are the two required attributes for the xml-stylesheet processing instruction. If the stylesheet is placed in the Web folder, Web Companion will find it and use it to transform the XML result. The request for an XSL document is:


The xml-stylesheet processing instruction is automatically added to the prolog of the result:

<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="Default.xsl"?>
<FMPDSORESULT xmlns="http://www.filemaker.com/fmpdsoresult">
      <LAYOUT />