8.4 Fixed-width Text Export

8.3 XML to HTML

All HTML documents produced can be viewed in a browser. The pages don't need to be served by a web browser. You may find that some CSS and JavaScript may not render correctly, depending on the browser version. Test all the examples in this section to see your results.

8.31 FMPXMLRESULT to HTML

You can find two examples of transforming exported XML into HTML in the FileMaker Pro 6 folder FileMaker Examples\XML Examples\ Export. You should study both of these stylesheets, as well as examples in the XSLT library, http://www.filemaker.com/xml/xslt_library.html, for more ideas on how to transform FileMaker Pro XML into HTML documents.

The simple_table.xsl stylesheet will create a basic HTML table showing the name of the database, the number of records, a row showing the field names, and one row for each record in your export. The complex_table.xsl stylesheet shows examples using the conditional <xsl:choose> and the functions position() and mod to determine the alternating background color of the rows.

8.32 FMPDSORESULT to HTML

This example is similar to the example in section 8.2. However, the output will be to method=HTML. The export and transformation will produce an HTML document. The data will be placed into an HTML table similar to the simple_table example. Instead of ROWs, we'll use the HTML element <TR>; and instead of COLs, we'll use the HTML element <TD>. This example will use the FMPDSORESULT instead of the FMPXMLRESULT export.

Example 1: Create a Simple HTML Table from FMPDSORESULT

  1. First make a copy of the transform3.xsl file and rename it dso2html1.xsl.

  2. Change the output method to "html" and indent to "yes".

  3. We need to make this an HTML document, so add these tags just after <xsl:template match="/">:

     <html><head><title>DSO2HTML1</title></head><body> 
  4. The HTML document needs to be closed, so add these tags just before </xsl:template>:

     </body></html> 
  5. Just before the first <xsl:for-each>, add the HTML element <table border="1">. For convenience, we'll show the table borders. Just after the final end tag, </xsl:for-each>, add the table close tag, </table>.

  6. Change the ROW element into the tr element. Don't forget the end tag! We won't use the MODID and RECORDID attributes at this time, so delete them from the stylesheet.

  7. Change the <COL><DATA> elements into the <td> element. Change </DATA></COL> into the </td> element.

  8. Save the changes to the stylesheet, as shown in Listing 8.13:

Listing 8.13: dso2html1.xsl

start example
 <?xml version='1.0' encoding='UTF-8' ?> <xsl:stylesheet version='1.0'   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'   xmlns:fm="http://www.filemaker.com/fmpdsoresult"   exclude-result-prefixes="fm">       <xsl:output version='1.0' encoding='UTF-8' indent='yes'         method='html' />       <xsl:template match="/">             <html>             <head><title>DSO2HTML</title></head>             <body>             <table border="1">             <xsl:for-each select="./fm:FMPDSORESULT/fm:ROW">                   <tr>                   <xsl:for-each select="./*">                         <td><xsl:value-of select="." /></td>                   </xsl:for-each>                   </tr>             </xsl:for-each>             </table>             </body>             </html>       </xsl:template> </xsl:stylesheet> 
end example

  1. Export some fields from any of your databases or use Export.fp5, found in Chapter 2.

  2. Choose File, Export Records and name your export dso2html1.htm.

  3. Select the FMPDSORESULT grammar.

  4. Check the Use XSL style sheet option and click the File button.

  5. Use the stylesheet dso2html1.xsl and click the Open button.

  6. Click the OK button and specify the fields to use in your new HTML table.

  7. Click the Export button and look at your new HTML document in a text editor and in a browser. The transformed HTML document should look similar to Listing 8.14. Look at the <META> element added just after the <head> element. The XSL processor added this.

Listing 8.14: dso2html1.htm

start example
 <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DSO2HTML</title> </head> <body> <table border="1"> <tr> <td>Beverly</td><td>Voth</td><td>KY</td><td>1.00</td><td></td> </tr> <tr> <td>Doug</td><td>Rowe</td><td>FL</td><td>2.00</td><td>1/15/2003</td> </tr> </table> </body> </html> 
end example

Example 2: Create an HTML Table with Column Names from Field Names

The table in Example 1 above has just the columns of data and does not show what is in the columns. This example will create a header row with the field names from the first row, as in transform5b.xsl. We'll also use the concept of another template to process the header row and use it inside the main template.

  1. Save a copy of dso2html1.xsl as dso2html2.xsl and make the following changes:
    After the <table border="1"> element, add the XSLT element below. We'll create another template to make the header row, but we must call it inside the current template.

     <xsl:call-template name="header" /> 
  2. Create the template named "header" and place it after the first template in the stylesheet.

     <xsl:template name="header">              <xsl:for-each select="./fm:FMPDSORESULT/                fm:ROW[1]/*">              <th><xsl:value-of select="name()" /></th>       </xsl:for-each> </xsl:template> 

The complete stylesheet is shown in Listing 8.15, and the result HTML is shown in Listing 8.16.

Listing 8.15: dso2html2.xsl

start example
 <?xml version='1.0' encoding='UTF-8' ?> <xsl:stylesheet version='1.0'   xmlns:xsl='http://www.w3.org/1999/XSL/Transform'   xmlns:fm="http://www.filemaker.com/fmpdsoresult"   exclude-result-prefixes="fm">       <xsl:output version='1.0' encoding='UTF-8' indent='yes'         method='html' />       <xsl:template match="/">             <html>             <head><title>DSO2HTML</title></head>             <body>             <table border="1">             <xsl:call-template name="header" />             <xsl:for-each select="./fm:FMPDSORESULT/fm:ROW">                   <tr>                   <xsl:for-each select="./*">                         <td><xsl:value-of select="." /></td>                   </xsl:for-each>                   </tr>             </xsl:for-each>             </table>             </body>             </html>       </xsl:template>       <xsl:template name="header">                   <xsl:for-each select="./fm:FMPDSORESULT/ fm:ROW[1]/*">                   <th><xsl:value-of select="name()" /></th>             </xsl:for-each>       </xsl:template> </xsl:stylesheet> 
end example

Listing 8.16: dso2html2.htm

start example
 <html> <head> <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>DSO2HTML</title> </head> <body> <table border="1"> <th>First_Name</th><th>Last_Name</th><th>State</th><th>Number</th>   <th>Date</th> <tr> <td>Beverly</td><td>Voth</td><td>KY</td><td>1.00</td><td></td> </tr> <tr> <td>Doug</td><td>Rowe</td><td>FL</td><td>2.00</td><td>1/15/2003</td> </tr> </table> </body> </html> 
end example

8.33 Subsummaries with FMPDSORESULT

Challenge: Revise the example XSLT subsummary.xsl to use the FMPDSORESULT. This stylesheet is found in the FileMaker Pro 6 folder FileMaker Examples\XML Examples\Export with the other examples. The stylesheet uses the <xsl:key> to group a particular column for summary. Hint: Instead of "fmp:FMPXMLRESULT/fmp:RESULTSET/ fmp:ROW", use "fmp:FMPDSORESULT/fmp:ROW", and instead of "fmp:COL[1]/fmp:DATA", use the name of the element (field name) to summarize. Change other references to the XML elements as needed.

The subsummary.xsl stylesheet also is a good example for using the <xsl:variable> element. We'll use that element to set parameters for our version of a "fixed-width" text export.



Filemaker Pro 6 Developer's Guide to XML(s)XSL
FileMaker Pro 6 Developers Guide to XML/XSL (Wordware Library for FileMaker)
ISBN: 155622043X
EAN: 2147483647
Year: 2003
Pages: 100
Authors: Beverly Voth

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net