Sunday, October 21, 2012

XML/XSL/HTML5 for reports instead of PDF

Since video of my actual presentation to the Denver HTML5 Meetup on October 22, 2012 won't be posted for a few more months, I quickly recorded the 10-minute YouTube below.

Below are the slides.

XML/XSL/HTML5 for reports instead of PDF

The official documentation on embedding XSL in XML actually dates from circa 2000.  Firefox still allows it.  Here is the overall structure of the .XML file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<!DOCTYPE doc [
<!ATTLIST xsl:stylesheet
 <!--Start XSL-->
 <xsl:stylesheet id="stylesheet"
  xmlns:xsl="" >

  <xsl:template match="xsl:stylesheet" />
  <xsl:template match="/doc">
     <style type="text/css">

       <!-- Your CSS goes here -->
     <script type="text/javascript">
       <!-- Your Javascript goes here -->

       <!-- Whatever is in here will get printed at the top of every page -->
       <!-- Main HTML, including "canvas" tags etc. -->

 <!--Start XML-->
  <datapoint x="2.1" y="3.0" />
  <datapoint x="2.9" y="5.2" />

Below is the bit of magic to draw up the XML data into Javascript memory space.  Assuming there is a Javascript constructor called ChartSeries that takes four parameters )name, array of x values, array of y values, color), the code below uses XSL to shove the x values inline in a comma-separated manner into the Javascript.

var mychartseries = new ChartSeries("Channel 1",[0
 <xsl:for-each select="seriesdata/datapoint">
  <xsl:value-of select="concat(',',@x)"/>
 <xsl:for-each select="seriesdata/datapoint">
  <xsl:value-of select="concat(',',@y)"/>
 ], "Yellow");

No comments: