<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" />

  <xsl:template match="sales">

        <!-- Define the size of the document -->
        <svg xmlns="http://www.w3.org/2000/svg" width="800" height="500" viewBox="0 0 600 100">

          <!-- The single group for this document. -->
          <g transform="translate(-10,-120)">

            <!-- Position the chart heading -->
            <text style="font-size:18" x="20" y="5">
              <xsl:value-of select="caption/heading"/>
              <xsl:text> by Region</xsl:text>
            </text>

            <!-- Display lines representing the x and y axes. -->
            <g style="stroke-width:2; stroke:black">
              <path d="M 40 230 L  40  10 L 40 230 L 200 230 Z"/>
            </g>

            <!-- y-axis labels -->
            <g style="text-anchor:end; font-size:9">
              <text x="36" y="203">10</text>
              <text x="36" y="183">20</text>
              <text x="36" y="163">30</text>
              <text x="36" y="143">40</text>
              <text x="36" y="123">50</text>
              <text x="36" y="103">60</text>
              <text x="36" y="83">70</text>
              <text x="36" y="63">80</text>
              <text x="36" y="43">90</text>
              <text x="36" y="23">100</text>
            </g>

            <!-- Draw one bar for each region element -->
            <xsl:for-each select="region">
              <!-- Cycle through a list of 5 colors based on the position of
               the current product in the list of products. -->
              <xsl:variable name="color-index" select="(position() mod 5) + 1"/>
              <xsl:variable name="color">
                <xsl:choose>
                  <xsl:when test="$color-index = 1">green</xsl:when>
                  <xsl:when test="$color-index = 2">red</xsl:when>
                  <xsl:when test="$color-index = 3">gray</xsl:when>
                  <xsl:when test="$color-index = 4">purple</xsl:when>
                  <xsl:otherwise>blue</xsl:otherwise>
                </xsl:choose>
              </xsl:variable>
              <xsl:variable name="x-offset" select="30 + (position() * 30)"/>
              <xsl:variable name="y-offset" select="230"/>

              <!-- Calculate height of bar -->
              <xsl:variable name="y" select="$y-offset - sum(product)"/>

              <!-- The colored bar with a black outline -->
              <path style="stroke-width:2; stroke:black; fill: {$color}" d="M {$x-offset - 10} {$y-offset} L {$x-offset - 10} {$y} L {$x-offset + 10} {$y} L {$x-offset + 10} {$y-offset} Z"/>

              <!-- Product index for bottom of bar -->
              <text style="text-anchor:middle" x="{$x-offset}" y="245">
                <xsl:value-of select="@name"/>
              </text>
            </xsl:for-each>
          </g>
        </svg>
	</xsl:template>
</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2006. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="no" name="Scenario1" userelativepaths="yes" externalpreview="no" url="chart.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/><scenario default="yes" name="SalesFigures" userelativepaths="yes" externalpreview="no" url="chart.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="no" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->