<xsl:stylesheet  version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 xmlns="http://www.w3.org/1999/xhtml" 
 xmlns:svg="http://www.w3.org/2000/svg"
 xmlns:html="http://www.w3.org/1999/xhtml" 
 xmlns:xlink="http://www.w3.org/1999/xlink" 
 xmlns:tb="http://www.treebuilder.de/namespace" > 
 
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
        
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()|text()"/>
</xsl:copy>
</xsl:template>
        
<xsl:template match="@*">
<xsl:copy/>
</xsl:template> 
        
<xsl:template match="processing-instruction()">
<xsl:copy>
                <xsl:apply-templates select="@*|node()|text()"/>
</xsl:copy>
</xsl:template>
        <xsl:template match="html:head">
<xsl:copy>
                  <xsl:if test="system-property('xsl:vendor')='Microsoft'">
                    <object id="AdobeSVG" classid="clsid:78156a80-c6a1-4bbf-8e6a-3cd390eeb4e2"></object>
                    <xsl:processing-instruction name="import">namespace="svg" implementation="#AdobeSVG"</xsl:processing-instruction>
                  </xsl:if>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template> 
        
        <xsl:template match="html:html">

                <xsl:choose>
                  <xsl:when test="system-property('xsl:vendor')='Microsoft'">
                    <html xmlns:svg="http://www.w3.org/2000/svg">
                    <xsl:apply-templates select="@*|node()"/>
                    </html>
                  </xsl:when>
                  <xsl:otherwise>
                  <xsl:copy>
                  <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
                  </xsl:otherwise>
                </xsl:choose>

</xsl:template>  

<xsl:template match="tb:chart">
<xsl:variable name="spaceRatio" select="0.8"/>
<xsl:variable name="leftspace" select="10"/>
<xsl:variable name="rightspace" select="10"/>
<xsl:variable name="topspace" select="30"/>
<xsl:variable name="bottomspace" select="35"/>
<xsl:variable name="realwidth" select="@width - ($leftspace + $rightspace)"/>
<xsl:variable name="realheight" select="@height - ($topspace + $bottomspace)"/>
<xsl:variable name="blockwidth" select="$realwidth div count(tb:nVPair)"/>
<xsl:variable name="rx" select="$blockwidth * $spaceRatio div 2"/>
<xsl:variable name="ry" select="8 * $spaceRatio"/>
<xsl:variable name="y0" select="@height - $bottomspace"/>
<xsl:variable name="max">
<xsl:for-each select="tb:nVPair">
<xsl:sort select="tb:value" order="descending" data-type="number"/>
<xsl:if test="position() = 1">
<xsl:value-of select="tb:value"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="dy" select="$realheight div $max"/>
<xsl:variable name="id" select="generate-id()"/>
<xsl:variable name="summe" select="sum(tb:nVPair/tb:value)"/>


  <svg:svg id="{$id}" width="{@width}" height="{@height}">
  <xsl:apply-templates select="@*"/>
  <svg:defs>
  <svg:linearGradient id="{$id}_G1" gradientUnits="objectBoundingBox">
<svg:stop offset="0%" stop-color="white" stop-opacity="0.3"/>
<svg:stop offset="10%" stop-color="white" stop-opacity="0.1"/>
<svg:stop offset="20%" stop-color="white" stop-opacity="0.2"/>
<svg:stop offset="30%" stop-color="#ffffff" stop-opacity="0.5"/>


<svg:stop offset="50%" stop-color="white" stop-opacity="0.2"/>
<svg:stop offset="100%" stop-color="white" stop-opacity="0"/>
</svg:linearGradient>
 </svg:defs> 
  <xsl:for-each select="tb:nVPair">
  <xsl:variable name="center" select="$leftspace + position() * $blockwidth - $blockwidth div 2 "/>
  <xsl:variable name="pfad"></xsl:variable>
  <svg:g>
  <xsl:apply-templates select="@*"/>
  <svg:ellipse fill-opacity="0.2" cx="{$center}" cy="{$y0}" rx="{$rx}" ry="{$ry}" stroke-opacity="0.5" stroke="{@fill}" fill="{@fill}"/>
  <svg:path fill-opacity="0.6" stroke="{@fill}" fill="{@fill}" d="M{$center - $rx} {$y0 - (tb:value * $dy)}
   a{$rx} {$ry} 0 0 0 {$rx * 2} 0
   v{tb:value * $dy}
   a{$rx} {$ry} 0 0 1 {-($rx * 2)} 0
   z"/>
  <svg:path fill="url(#{$id}_G1)" d="M{$center - $rx} {$y0 - (tb:value * $dy)}
   a{$rx} {$ry} 0 0 0 {$rx * 2} 0
   v{tb:value * $dy}
   a{$rx} {$ry} 0 0 1 {-($rx * 2)} 0
   z"/>
  <svg:ellipse fill-opacity="0.6" cx="{$center}" cy="{$y0 - (tb:value * $dy)}" rx="{$rx}" ry="{$ry}" stroke="{@fill}" fill="{@fill}"/>
  
  <svg:text x="{$center}" y="{$y0 + 10 + 20}" text-anchor="middle">
  <xsl:apply-templates select="tb:name/@*"/>
  <xsl:value-of select="tb:name"/></svg:text>
  <svg:text x="{$center }" y="{$y0 - (tb:value * $dy) - 15}" text-anchor="middle">
  <xsl:apply-templates select="tb:value/@*"/>
  <xsl:value-of select="floor(tb:value div $summe * 1000) div 10"/> %</svg:text>
  </svg:g>
  </xsl:for-each>
 </svg:svg>	
</xsl:template>

 </xsl:stylesheet>
