Example 16-9: Producing Scalable Vector Graphics with XSLT

<!-- SalChart.xsl: Draw a colorful bar chart using SVG-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Include the stylesheet with the "drawBar" template -->
  <xsl:include href="LabeledSVGBar.xsl"/>
  <!-- Width/Height size of chart area-->
  <xsl:variable name="chartSize" select="1000"/>
  <!-- Select max value of salaries being charted -->
  <xsl:variable name="maxSalary">
    <xsl:for-each select="/ROWSET/ROW">
      <xsl:sort data-type="number" select="SAL" order="descending"/>
      <xsl:if test="position()=1">
        <xsl:value-of select="SAL"/>
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>
  <!-- Select count of number of ROW's -->
  <xsl:variable name="totalEmps">
    <xsl:value-of select="count(/ROWSET/ROW)"/>
  </xsl:variable>
  <!--
  | SVG Viewers expect XML Document with SVG DTD and a Media Type of "image/svg"
  +-->
  <xsl:output standalone="yes" doctype-system="svg-19990812.dtd"
             media-type="image/svg" indent="yes"/>
  <!-- Root Template creates outmost <svg> and <g> graphics element-->
  <xsl:template match="/">
   <svg width="{$chartSize}" height="{$chartSize}">
     <xsl:comment><xsl:value-of select="$maxSalary"/></xsl:comment>
     <desc>Salary Chart</desc>
     <g style="stroke:#000000;stroke-width:1;font-family:Arial;font-size:16">
       <!-- Loop over each ROW in the ROWSET -->
       <xsl:for-each select="ROWSET/ROW">
         <!-- Call the "drawBar" template to draw each bar -->
         <xsl:call-template name="drawBar">
           <xsl:with-param name="barIndex"   select="position()"/>
           <xsl:with-param name="label"      select="ENAME"/>
           <xsl:with-param name="value"      select="SAL"/>
           <xsl:with-param name="chartWidth" select="$chartSize"/>
           <xsl:with-param name="maxValue"   select="$maxSalary"/>
           <xsl:with-param name="rowCount"   select="$totalEmps"/>
         </xsl:call-template>
       </xsl:for-each>
     </g>
   </svg>
  </xsl:template>
</xsl:stylesheet>