7.5 XSL and HTML

7.5 XSL and HTML

An XSL stylesheet can be used to transform XML into HTML, a more common method of web delivery. The HTML markup must conform to the XHTML standards. See Chapter 6 for more information about HTML as well-formed XML tags. In addition, Cascading Style Sheets (CSS) may be used in the HTML to provide the formatting. The preferred method of CSS inclusion is with the XHTML <link> element:

<link rel="stylesheet" type="text/css" href="myStyles.css" />

The table row <tr> is generally a repeated element and may be dynamically produced by the XSL elements <xsl:template> or <xsl:for-each>. Furthermore, the table cell element <td> may be dynamically produced by using the templates for field elements. Listing 7.9 shows a simple table produced with the FMPDSORESULT. You can see more XSL examples in the FileMaker Examples folder included with FileMaker Pro 6 and in the XSLT library on the web site http://www.filemaker.com/xml/xslt_library.html.

Listing 7.9: Dynamic table
Start example
<xsl:template match="/">
      <table border="1" cellpadding="3" cellspacing="2">
            <xsl:for-each select="fmp:ROW">
            <tr>
                  <xsl:for-each select="./*">
<!-- get all children and display the results -->
                  <td>
                        <xsl:value-of select="." />
                  </td>
                  </xsl:for-each>
            </tr>
            </xsl:for-each>
      </table>
</xsl:template>
End example