title: creating beams of variable length with xslt
body: <p>From the following xml data:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;?xml-stylesheet href="kandidaten.xsl" type="text/xsl"?&gt; 
  &lt;auswertung&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Peter&lt;/name&gt;
          &lt;punkte&gt;67&lt;/punkte&gt;
      &lt;/kandidat&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Karl&lt;/name&gt;
          &lt;punkte&gt;87&lt;/punkte&gt;
      &lt;/kandidat&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Anita&lt;/name&gt;
          &lt;punkte&gt;36&lt;/punkte&gt;
      &lt;/kandidat&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Rosi&lt;/name&gt;
          &lt;punkte&gt;67&lt;/punkte&gt;
      &lt;/kandidat&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Heiner&lt;/name&gt;
          &lt;punkte&gt;50&lt;/punkte&gt;
      &lt;/kandidat&gt;
      &lt;kandidat&gt;
          &lt;name&gt;Paul&lt;/name&gt;
          &lt;punkte&gt;45&lt;/punkte&gt;
      &lt;/kandidat&gt;
  &lt;/auswertung&gt;
  </code></pre>
  
  <p>I want to create the following output with xslt:</p>
  
  <p><a href="https://i.stack.imgur.com/pfObF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pfObF.png" alt="enter image description here"></a></p>
  
  <p>To this end I wrote the following xslt code:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="xs"
      version="2.0"&gt;
  
  
  &lt;xsl:template match="auswertung"&gt;
      &lt;html&gt;
          &lt;head&gt;
              &lt;title&gt;Kandidaten&lt;/title&gt;
          &lt;/head&gt;
          &lt;body&gt;
              &lt;h1&gt;Kandidaten und ihre Punkte&lt;/h1&gt;
              &lt;hr/&gt;
              &lt;table&gt;
                  &lt;xsl:apply-templates select="kandidat"&gt;
                      &lt;xsl:sort select="punkte" order="descending"&gt;&lt;/xsl:sort&gt;
                  &lt;/xsl:apply-templates&gt;
              &lt;/table&gt;
  
          &lt;/body&gt;
      &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="kandidat"&gt;
  
      &lt;tr&gt;
          &lt;td&gt;
              &lt;xsl:value-of select="name/text()"/&gt;
          &lt;/td&gt;
  
  &lt;!-- second columns of table is supposed to contain the --&gt;
  &lt;!-- points  ("punkte") of the respective candidate ("kandidat") --&gt;
          &lt;td&gt;
  
  &lt;!-- second column contains a paragraph whose background-color is blue --&gt;
              &lt;p bgcolor="#0000ff"&gt;
                 &lt;xsl:call-template name="create_empty_space"&gt;
                      &lt;xsl:with-param name="count" select="punkte/text()"/&gt;
                      &lt;xsl:with-param name="number" select="punkte/text()"/&gt;
                 &lt;/xsl:call-template&gt;
             &lt;/p&gt;         
          &lt;/td&gt;                           
      &lt;/tr&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template name="create_empty_space"&gt;
      &lt;xsl:param name="count"/&gt;
      &lt;xsl:param name="number"/&gt;
  
  &lt;!-- print number (points achieved by candidate) in the middle of the beam --&gt;                 
  &lt;xsl:if test="$count = round($number div 2)"&gt;
          &lt;font color="#ffff00"&gt;
              &lt;xsl:value-of select="$number"/&gt;
          &lt;/font&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:if test="$count &gt; 0"&gt; 
  
  
    &lt;!-- amount of empty space created is supposed to depend on the number of --&gt;
    &lt;!--points, therefore function "create_empty_space" is called recursively--&gt;
    &lt;!-- depending on the number of points --&gt;
    &lt;!--... example: if points==20, function is called 20 times --&gt;                                 
  
  &lt;xsl:text&gt; &lt;/xsl:text&gt;
          &lt;xsl:call-template name="create_empty_space"&gt;
              &lt;xsl:with-param name="count" select="$count - 1"/&gt;
              &lt;xsl:with-param name="number" select="$number"/&gt;
          &lt;/xsl:call-template&gt;
      &lt;/xsl:if&gt;
  &lt;/xsl:template&gt;
  
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>When I run the code, all beams have the same size, though.
  How can I make the length of the beams correspond to the number of points of the respective candidate?</p>