Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/delibero.git

Spacing.

Author Dave Jarvis <email>
Date 2014-08-03 00:54:15 GMT-0700
Commit 753925b01e8fb5c63a6569160e7da05b0e076fb8
Parent 68346d1
Delta 308 lines added, 309 lines removed, 1-line decrease
xml/chart.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:include href="math.xsl" />
-
- <xsl:variable name="base_colour" select="'46A5E5'" />
- <xsl:variable name="stroke_colour" select="'white'" />
- <xsl:variable name="width" select="200" />
- <xsl:variable name="height" select="$width" />
-
- <xsl:template match="title" mode="piechart">
- <div class="title"><xsl:apply-templates /></div>
- </xsl:template>
+<xsl:include href="math.xsl" />
- <!-- Convert XML data into a pie chart. -->
- <xsl:template match="dataset" mode="piechart">
+<xsl:variable name="base_colour" select="'46A5E5'" />
+<xsl:variable name="stroke_colour" select="'white'" />
+<xsl:variable name="width" select="200" />
+<xsl:variable name="height" select="$width" />
- <!-- Number of pie pieces. -->
- <xsl:variable name="pieces" select="count(data)" />
+<xsl:template match="title" mode="piechart">
+ <div class="title"><xsl:apply-templates /></div>
+</xsl:template>
- <!-- Calculate the total value for all pieces (for percentages). -->
- <xsl:variable name="total" select="sum(//value)" />
+<!-- Convert XML data into a pie chart. -->
+<xsl:template match="dataset" mode="piechart">
+ <!-- Number of wedges. -->
+ <xsl:variable name="wedges" select="count(data)" />
- <div class="chart">
- <div class="graph">
- <svg width="{$width}" height="{$height}" version="1.1" xmlns="http://www.w3.org/2000/svg">
- <xsl:for-each select="data">
- <xsl:apply-templates select="value" mode="piechart">
- <xsl:with-param name="colour">
- <xsl:call-template name="fill">
- <xsl:with-param name="piece" select="position()" />
- <xsl:with-param name="pieces" select="$pieces" />
- <xsl:with-param name="colour" select="$base_colour" />
- </xsl:call-template>
- </xsl:with-param>
- <xsl:with-param name="total" select="$total" />
- <xsl:with-param name="runningTotal" select="sum(preceding-sibling::data/value)" />
- <xsl:with-param name="radius" select="$width * 0.5" />
- </xsl:apply-templates>
- </xsl:for-each>
- </svg>
- </div>
- <!-- SVG 1.1 has no text flow abilities: legend is plain HTML. -->
- <div class="legend">
- <xsl:for-each select="//name">
- <xsl:variable name="colour">
- <xsl:call-template name="fill">
- <xsl:with-param name="piece" select="position()" />
- <xsl:with-param name="pieces" select="$pieces" />
- <xsl:with-param name="colour" select="$base_colour" />
- </xsl:call-template>
- </xsl:variable>
+ <!-- Calculate the total value for all wedges (for percentages). -->
+ <xsl:variable name="total" select="sum(//value)" />
- <xsl:variable name="percent" select="concat(.,' (',format-number(../value div $total, '0.00%'),')')" />
-
- <div class="piece">
- <div class="bullet" style="background-color:{$colour}" />
- <xsl:value-of select="$percent" />
- </div>
+ <div class="chart">
+ <div class="graph">
+ <svg width="{$width}" height="{$height}" version="1.1" xmlns="http://www.w3.org/2000/svg">
+ <xsl:for-each select="data">
+ <xsl:apply-templates select="value" mode="piechart">
+ <xsl:with-param name="colour">
+ <xsl:call-template name="fill">
+ <xsl:with-param name="wedge" select="position()" />
+ <xsl:with-param name="wedges" select="$wedges" />
+ <xsl:with-param name="colour" select="$base_colour" />
+ </xsl:call-template>
+ </xsl:with-param>
+ <xsl:with-param name="total" select="$total" />
+ <xsl:with-param name="runningTotal" select="sum(preceding-sibling::data/value)" />
+ <xsl:with-param name="radius" select="$width * 0.5" />
+ </xsl:apply-templates>
</xsl:for-each>
- </div>
+ </svg>
</div>
- </xsl:template>
+ <!-- SVG 1.1 has no text flow abilities: legend is plain HTML. -->
+ <div class="legend">
+ <xsl:for-each select="//name">
+ <xsl:variable name="colour">
+ <xsl:call-template name="fill">
+ <xsl:with-param name="wedge" select="position()" />
+ <xsl:with-param name="wedges" select="$wedges" />
+ <xsl:with-param name="colour" select="$base_colour" />
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="percent" select="concat(.,' (',format-number(../value div $total, '0.00%'),')')" />
+
+ <div class="piece">
+ <div class="bullet" style="background-color:{$colour}" />
+ <xsl:value-of select="$percent" />
+ </div>
+ </xsl:for-each>
+ </div>
+ </div>
+</xsl:template>
+
+<!-- http://www.svgopen.org/2003/papers/CreatingSVGPieChartsThroughWebService/ -->
+<!-- http://jbkflex.wordpress.com/2011/07/28/creating-a-svg-pie-chart-html5/ -->
+<!-- http://www.codestore.net/store.nsf/unid/epsd-5dtt4l -->
+<xsl:template match="value" mode="piechart">
+ <xsl:param name="colour" />
+ <xsl:param name="total" />
+ <xsl:param name="runningTotal" />
+ <xsl:param name="radius" />
- <!-- http://www.svgopen.org/2003/papers/CreatingSVGPieChartsThroughWebService/ -->
- <!-- http://jbkflex.wordpress.com/2011/07/28/creating-a-svg-pie-chart-html5/ -->
- <!-- http://www.codestore.net/store.nsf/unid/epsd-5dtt4l -->
- <xsl:template match="value" mode="piechart">
- <xsl:param name="colour" />
- <xsl:param name="total" />
- <xsl:param name="runningTotal" />
- <xsl:param name="radius" />
-
- <xsl:variable name="title" select="concat(../name,' (',format-number(. div $total, '0.00%'),')')" />
- <xsl:variable name="r" select="$radius" />
-
- <!-- Set the start and ending angles. -->
- <xsl:variable name="sa" select="360.0 * ($runningTotal div $total)" />
- <xsl:variable name="ea" select="360.0 * (($runningTotal + .) div $total)" />
-
- <xsl:variable name="x1">
- <xsl:call-template name="sine">
- <xsl:with-param name="degrees" select="-$sa" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="y1">
- <xsl:call-template name="sine">
- <xsl:with-param name="degrees" select="(-$sa - 90)" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="x2">
- <xsl:call-template name="sine">
- <xsl:with-param name="degrees" select="-$ea" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="y2">
- <xsl:call-template name="sine">
- <xsl:with-param name="degrees" select="(-$ea - 90)" />
- </xsl:call-template>
- </xsl:variable>
+ <xsl:variable name="title" select="concat(../name,' (',format-number(. div $total, '0.00%'),')')" />
+ <xsl:variable name="r" select="$radius" />
+
+ <!-- Set the start and ending angles. -->
+ <xsl:variable name="sa" select="360.0 * ($runningTotal div $total)" />
+ <xsl:variable name="ea" select="360.0 * (($runningTotal + .) div $total)" />
+
+ <xsl:variable name="x1">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="degrees" select="-$sa" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="y1">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="degrees" select="(-$sa - 90)" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="x2">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="degrees" select="-$ea" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="y2">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="degrees" select="(-$ea - 90)" />
+ </xsl:call-template>
+ </xsl:variable>
- <xsl:variable name="sweep">
- <xsl:choose>
- <xsl:when test="($ea - $sa &gt; 180)">1</xsl:when>
- <xsl:otherwise>0</xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <path xmlns="http://www.w3.org/2000/svg"
- fill="{$colour}"
- title="{$title}"
- stroke="{$stroke_colour}"
- transform="translate({$radius},{$radius})"
- d="{concat('M 0 0 L ', $x1 * $r, ' ', $y1 * $r, ' A ', $r, ' ', $r, ' 0 ', $sweep, ' 0 ', $x2 * $r, ' ', $y2 * $r, ' Z' )}" />
- </xsl:template>
+ <xsl:variable name="sweep">
+ <xsl:choose>
+ <xsl:when test="($ea - $sa &gt; 180)">1</xsl:when>
+ <xsl:otherwise>0</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <path xmlns="http://www.w3.org/2000/svg"
+ fill="{$colour}"
+ title="{$title}"
+ stroke="{$stroke_colour}"
+ transform="translate({$radius},{$radius})"
+ d="{concat('M 0 0 L ', $x1 * $r, ' ', $y1 * $r, ' A ', $r, ' ', $r, ' 0 ', $sweep, ' 0 ', $x2 * $r, ' ', $y2 * $r, ' Z' )}" />
+</xsl:template>
- <!-- http://en.wikipedia.org/wiki/HSL_and_HSV -->
- <xsl:template name="fill">
- <xsl:param name="piece" />
- <xsl:param name="pieces" />
- <xsl:param name="colour" />
+<!-- http://en.wikipedia.org/wiki/HSL_and_HSV -->
+<xsl:template name="fill">
+ <xsl:param name="wedge" />
+ <xsl:param name="wedges" />
+ <xsl:param name="colour" />
- <xsl:variable name="r">
- <xsl:call-template name="hex2dec">
- <xsl:with-param name="hex" select="substring( $colour, 1, 2 )" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="g">
- <xsl:call-template name="hex2dec">
- <xsl:with-param name="hex" select="substring( $colour, 3, 2 )" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="b">
- <xsl:call-template name="hex2dec">
- <xsl:with-param name="hex" select="substring( $colour, 5, 2 )" />
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="alpha" select="(2 * $r - $g - $b) * 0.5" />
- <xsl:variable name="beta" select="0.86602540378 * ($g - $b)" />
-
- <xsl:variable name="base_hue">
- <xsl:call-template name="atan2">
- <xsl:with-param name="x" select="$alpha" />
- <xsl:with-param name="y" select="$beta" />
- </xsl:call-template>
- </xsl:variable>
+ <xsl:variable name="r">
+ <xsl:call-template name="hex2dec">
+ <xsl:with-param name="hex" select="substring( $colour, 1, 2 )" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="g">
+ <xsl:call-template name="hex2dec">
+ <xsl:with-param name="hex" select="substring( $colour, 3, 2 )" />
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="b">
+ <xsl:call-template name="hex2dec">
+ <xsl:with-param name="hex" select="substring( $colour, 5, 2 )" />
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="alpha" select="(2 * $r - $g - $b) * 0.5" />
+ <xsl:variable name="beta" select="0.86602540378 * ($g - $b)" />
+
+ <xsl:variable name="base_hue">
+ <xsl:call-template name="atan2">
+ <xsl:with-param name="x" select="$alpha" />
+ <xsl:with-param name="y" select="$beta" />
+ </xsl:call-template>
+ </xsl:variable>
- <xsl:variable name="chroma">
- <xsl:call-template name="sqrt">
- <xsl:with-param name="n" select="($alpha * $alpha) + ($beta * $beta)" />
+ <xsl:variable name="chroma">
+ <xsl:call-template name="sqrt">
+ <xsl:with-param name="n" select="($alpha * $alpha) + ($beta * $beta)" />
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="value">
+ <xsl:variable name="max_rg">
+ <xsl:call-template name="max">
+ <xsl:with-param name="a" select="$r" />
+ <xsl:with-param name="b" select="$g" />
</xsl:call-template>
</xsl:variable>
-
- <xsl:variable name="value">
- <xsl:variable name="max_rg">
- <xsl:call-template name="max">
- <xsl:with-param name="a" select="$r" />
- <xsl:with-param name="b" select="$g" />
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="max_gb">
- <xsl:call-template name="max">
- <xsl:with-param name="a" select="$g" />
- <xsl:with-param name="b" select="$b" />
- </xsl:call-template>
- </xsl:variable>
+ <xsl:variable name="max_gb">
<xsl:call-template name="max">
- <xsl:with-param name="a" select="$max_rg" />
- <xsl:with-param name="b" select="$max_gb" />
+ <xsl:with-param name="a" select="$g" />
+ <xsl:with-param name="b" select="$b" />
</xsl:call-template>
</xsl:variable>
-
- <xsl:variable name="h_rotate" select="($base_hue + ((240 div $pieces) * $piece) mod 240)"></xsl:variable>
- <xsl:variable name="h_prime" select="$h_rotate div 60.0" />
- <xsl:variable name="h_mod" select="$h_prime mod 2 - 1" />
- <xsl:variable name="h_abs" select="($h_mod &gt;= 0) * $h_mod - not($h_mod &gt;= 0) * $h_mod" />
-
- <xsl:variable name="x" select="$chroma * (1 - $h_abs)" />
- <xsl:variable name="m" select="$value - $chroma" />
- <xsl:variable name="c" select="$chroma" />
-
- <xsl:variable name="cm" select="round( $c + $m )" />
- <xsl:variable name="xm" select="round( $x + $m )" />
- <xsl:variable name="zm" select="round( 0 + $m )" />
+ <xsl:call-template name="max">
+ <xsl:with-param name="a" select="$max_rg" />
+ <xsl:with-param name="b" select="$max_gb" />
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="h_rotate" select="($base_hue + ((240 div $wedges) * $wedge) mod 240)"></xsl:variable>
+ <xsl:variable name="h_prime" select="$h_rotate div 60.0" />
+ <xsl:variable name="h_mod" select="$h_prime mod 2 - 1" />
+ <xsl:variable name="h_abs" select="($h_mod &gt;= 0) * $h_mod - not($h_mod &gt;= 0) * $h_mod" />
+
+ <xsl:variable name="x" select="$chroma * (1 - $h_abs)" />
+ <xsl:variable name="m" select="$value - $chroma" />
+ <xsl:variable name="c" select="$chroma" />
+
+ <xsl:variable name="cm" select="round( $c + $m )" />
+ <xsl:variable name="xm" select="round( $x + $m )" />
+ <xsl:variable name="zm" select="round( 0 + $m )" />
- <xsl:choose>
- <xsl:when test="0 &lt;= $h_prime and $h_prime &lt; 1">
- <xsl:value-of select="concat('rgb(', $cm, ',', $xm, ',', $zm, ')' )" />
- </xsl:when>
- <xsl:when test="1 &lt;= $h_prime and $h_prime &lt; 2">
- <xsl:value-of select="concat('rgb(', $xm, ',', $cm, ',', $zm, ')' )" />
- </xsl:when>
- <xsl:when test="2 &lt;= $h_prime and $h_prime &lt; 3">
- <xsl:value-of select="concat('rgb(', $zm, ',', $cm, ',', $xm, ')' )" />
- </xsl:when>
- <xsl:when test="3 &lt;= $h_prime and $h_prime &lt; 4">
- <xsl:value-of select="concat('rgb(', $zm, ',', $xm, ',', $cm, ')' )" />
- </xsl:when>
- <xsl:when test="4 &lt;= $h_prime and $h_prime &lt; 5">
- <xsl:value-of select="concat('rgb(', $xm, ',', $zm, ',', $cm, ')' )" />
- </xsl:when>
- <xsl:when test="5 &lt;= $h_prime and $h_prime &lt; 6">
- <xsl:value-of select="concat('rgb(', $cm, ',', $zm, ',', $xm, ')' )" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="concat('rgb(', $r, ',', $g, ',', $b, ')' )" />
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
+ <xsl:choose>
+ <xsl:when test="0 &lt;= $h_prime and $h_prime &lt; 1">
+ <xsl:value-of select="concat('rgb(', $cm, ',', $xm, ',', $zm, ')' )" />
+ </xsl:when>
+ <xsl:when test="1 &lt;= $h_prime and $h_prime &lt; 2">
+ <xsl:value-of select="concat('rgb(', $xm, ',', $cm, ',', $zm, ')' )" />
+ </xsl:when>
+ <xsl:when test="2 &lt;= $h_prime and $h_prime &lt; 3">
+ <xsl:value-of select="concat('rgb(', $zm, ',', $cm, ',', $xm, ')' )" />
+ </xsl:when>
+ <xsl:when test="3 &lt;= $h_prime and $h_prime &lt; 4">
+ <xsl:value-of select="concat('rgb(', $zm, ',', $xm, ',', $cm, ')' )" />
+ </xsl:when>
+ <xsl:when test="4 &lt;= $h_prime and $h_prime &lt; 5">
+ <xsl:value-of select="concat('rgb(', $xm, ',', $zm, ',', $cm, ')' )" />
+ </xsl:when>
+ <xsl:when test="5 &lt;= $h_prime and $h_prime &lt; 6">
+ <xsl:value-of select="concat('rgb(', $cm, ',', $zm, ',', $xm, ')' )" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="concat('rgb(', $r, ',', $g, ',', $b, ')' )" />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
</xsl:stylesheet>
xml/math.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
- <xsl:variable name="PI">3.14159265358979323846</xsl:variable>
+<xsl:variable name="PI">3.14159265358979323846</xsl:variable>
- <!-- Find the square root of a number (n). -->
- <xsl:template name="sqrt">
- <xsl:param name="n" select="0" />
- <!-- Used internally -->
- <xsl:param name="try" select="1" />
- <!-- The current iteration, checked against maxiter to limit loop count -->
- <xsl:param name="iter" select="1"/>
- <!-- Used to avoid infinite loops (maximum iteration) -->
- <xsl:param name="maxiter" select="20"/>
+<!-- Find the square root of a number (n). -->
+<xsl:template name="sqrt">
+ <xsl:param name="n" select="0" />
+ <!-- Used internally -->
+ <xsl:param name="try" select="1" />
+ <!-- The current iteration, checked against maxiter to limit loop count -->
+ <xsl:param name="iter" select="1"/>
+ <!-- Used to avoid infinite loops (maximum iteration) -->
+ <xsl:param name="maxiter" select="20"/>
- <!-- Nate Austin's implementation using Newton's method -->
- <xsl:choose>
- <xsl:when test="$try * $try = $n or $iter &gt; $maxiter">
- <xsl:value-of select="$try" />
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="sqrt">
- <xsl:with-param name="n" select="$n"/>
- <xsl:with-param name="try" select="$try - (($try * $try - $n) div (2 * $try))"/>
- <xsl:with-param name="iter" select="$iter + 1"/>
- <xsl:with-param name="maxiter" select="$maxiter"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
+ <!-- Nate Austin's implementation using Newton's method -->
+ <xsl:choose>
+ <xsl:when test="$try * $try = $n or $iter &gt; $maxiter">
+ <xsl:value-of select="$try" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="sqrt">
+ <xsl:with-param name="n" select="$n"/>
+ <xsl:with-param name="try" select="$try - (($try * $try - $n) div (2 * $try))"/>
+ <xsl:with-param name="iter" select="$iter + 1"/>
+ <xsl:with-param name="maxiter" select="$maxiter"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!--
+ | Calculates sin(x), given x in degrees (not radians):
+ | x(1 - (x^2/2*3)(1 - (x^2/4*5)(1 - (x^2/6*7))))
+ +-->
+<xsl:template name="sine">
+ <xsl:param name="degrees" />
+ <xsl:param name="radians" select="$degrees * $PI div 180" />
+ <xsl:param name="iter" select="31" />
+ <xsl:param name="result" select="1" />
- <!--
- | Calculates sin(x), given x in degrees (not radians):
- | x(1 - (x^2/2*3)(1 - (x^2/4*5)(1 - (x^2/6*7))))
- +-->
- <xsl:template name="sine">
- <xsl:param name="degrees" />
- <xsl:param name="radians" select="$degrees * $PI div 180" />
- <xsl:param name="iter" select="31" />
- <xsl:param name="result" select="1" />
-
- <xsl:variable name="term" select="($radians * $radians) div (($iter - 1) * $iter)" />
-
- <xsl:choose>
- <xsl:when test="$iter &gt; 2">
- <xsl:call-template name="sine">
- <xsl:with-param name="radians" select="$radians" />
- <xsl:with-param name="iter" select="$iter - 2" />
- <xsl:with-param name="result" select="1 - ($term * $result)" />
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise><xsl:value-of select="$radians * $result" /></xsl:otherwise>
- </xsl:choose>
- </xsl:template>
+ <xsl:variable name="term" select="($radians * $radians) div (($iter - 1) * $iter)" />
+
+ <xsl:choose>
+ <xsl:when test="$iter &gt; 2">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="radians" select="$radians" />
+ <xsl:with-param name="iter" select="$iter - 2" />
+ <xsl:with-param name="result" select="1 - ($term * $result)" />
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="$radians * $result" /></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
- <!-- Calculates the normalized arc tangent form. -->
- <xsl:template name="atan2">
- <xsl:param name="y"/>
- <xsl:param name="x"/>
- <!-- http://lists.apple.com/archives/PerfOptimization-dev/2005/Jan/msg00051.html -->
- <!-- http://permalink.gmane.org/gmane.text.xml.xslt.extensions/840 -->
- <xsl:variable name="PIBY2" select="$PI div 2.0"/>
- <xsl:choose>
- <xsl:when test="$x = 0.0">
+<!-- Calculates the normalized arc tangent form. -->
+<xsl:template name="atan2">
+ <xsl:param name="y"/>
+ <xsl:param name="x"/>
+ <!-- http://lists.apple.com/archives/PerfOptimization-dev/2005/Jan/msg00051.html -->
+ <!-- http://permalink.gmane.org/gmane.text.xml.xslt.extensions/840 -->
+ <xsl:variable name="PIBY2" select="$PI div 2.0"/>
+ <xsl:choose>
+ <xsl:when test="$x = 0.0">
+ <xsl:choose>
+ <xsl:when test="($y &gt; 0.0)">
+ <xsl:value-of select="$PIBY2"/>
+ </xsl:when>
+ <xsl:when test="($y &lt; 0.0)">
+ <xsl:value-of select="-$PIBY2"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number(NaN)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="z" select="$y div $x"/>
+ <xsl:variable name="absZ">
<xsl:choose>
- <xsl:when test="($y &gt; 0.0)">
- <xsl:value-of select="$PIBY2"/>
- </xsl:when>
- <xsl:when test="($y &lt; 0.0)">
- <xsl:value-of select="-$PIBY2"/>
+ <xsl:when test="$z &lt; 0.0">
+ <xsl:value-of select="-number($z)"/>
</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="number(NaN)"/>
+ <xsl:value-of select="number($z)"/>
</xsl:otherwise>
</xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="z" select="$y div $x"/>
- <xsl:variable name="absZ">
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="($absZ &lt; 1.0)">
+ <xsl:variable name="f1Z" select="$z div (1.0 + 0.28*$z*$z)"/>
<xsl:choose>
- <xsl:when test="$z &lt; 0.0">
- <xsl:value-of select="-number($z)"/>
+ <xsl:when test="($x &lt; 0.0) and ($y &lt; 0.0)">
+ <xsl:value-of select="$f1Z - $PI"/>
+ </xsl:when>
+ <xsl:when test="($x &lt; 0.0)">
+ <xsl:value-of select="$f1Z + $PI"/>
</xsl:when>
<xsl:otherwise>
- <xsl:value-of select="number($z)"/>
+ <xsl:value-of select="$f1Z"/>
</xsl:otherwise>
</xsl:choose>
- </xsl:variable>
- <xsl:choose>
- <xsl:when test="($absZ &lt; 1.0)">
- <xsl:variable name="f1Z" select="$z div (1.0 + 0.28*$z*$z)"/>
- <xsl:choose>
- <xsl:when test="($x &lt; 0.0) and ($y &lt; 0.0)">
- <xsl:value-of select="$f1Z - $PI"/>
- </xsl:when>
- <xsl:when test="($x &lt; 0.0)">
- <xsl:value-of select="$f1Z + $PI"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$f1Z"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="f2Z" select="$PIBY2 - ($z div ($z*$z + 0.28))"/>
- <xsl:choose>
- <xsl:when test="($y &lt; 0.0)">
- <xsl:value-of select="$f2Z - $PI"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$f2Z"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="f2Z" select="$PIBY2 - ($z div ($z*$z + 0.28))"/>
+ <xsl:choose>
+ <xsl:when test="($y &lt; 0.0)">
+ <xsl:value-of select="$f2Z - $PI"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$f2Z"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Returns the larger of two values (a, b). -->
+<xsl:template name="max">
+ <xsl:param name="a" select="0" />
+ <xsl:param name="b" select="0" />
- <!-- Returns the larger of two values (a, b). -->
- <xsl:template name="max">
- <xsl:param name="a" select="0" />
- <xsl:param name="b" select="0" />
-
- <xsl:if test="$a &gt;= $b"><xsl:value-of select="$a" /></xsl:if>
- <xsl:if test="$a &lt; $b"><xsl:value-of select="$b" /></xsl:if>
- </xsl:template>
+ <xsl:if test="$a &gt;= $b"><xsl:value-of select="$a" /></xsl:if>
+ <xsl:if test="$a &lt; $b"><xsl:value-of select="$b" /></xsl:if>
+</xsl:template>
- <!-- Converts a two-digit hexadecimal number to decimal. -->
- <xsl:template name="hex2dec">
- <xsl:param name="hex" select="'00'" />
+<!-- Converts a two-digit hexadecimal number to decimal. -->
+<xsl:template name="hex2dec">
+ <xsl:param name="hex" select="'00'" />
- <xsl:variable name="digits" select="'0123456789ABCDEF'" />
- <xsl:variable name="X" select="substring( $hex, 1, 1 )" />
- <xsl:variable name="Y" select="substring( $hex, 2, 1 )" />
- <xsl:variable name="Xval" select="string-length(substring-before($digits,$X))" />
- <xsl:variable name="Yval" select="string-length(substring-before($digits,$Y))" />
-
- <xsl:value-of select="16 * $Xval + $Yval" />
- </xsl:template>
+ <xsl:variable name="digits" select="'0123456789ABCDEF'" />
+ <xsl:variable name="X" select="substring( $hex, 1, 1 )" />
+ <xsl:variable name="Y" select="substring( $hex, 2, 1 )" />
+ <xsl:variable name="Xval" select="string-length(substring-before($digits,$X))" />
+ <xsl:variable name="Yval" select="string-length(substring-before($digits,$Y))" />
+
+ <xsl:value-of select="16 * $Xval + $Yval" />
+</xsl:template>
</xsl:stylesheet>