Dave Jarvis' Repositories

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

Reorganized XSL in preparation to add text editor.

AuthorDave Jarvis <email>
Date2014-12-05 14:49:46 GMT-0800
Commit10518f557fb5ae2ee6469b516717604ae8477004
Parentebbc456
xml/.gitignore
hColumns/
+wysiwyg
xml/build.sh
#!/bin/bash
-# Use XSLT 2.0 to build the example HTML pages from the template.
+# Use XSLT 2.0 to build the example HTML pages from the pages template.
java -jar /home/jarvisd/dev/piechartdemo/saxon9he.jar \
- -s:pages.xml -xsl:template.xsl
+ -s:pages.xml -xsl:pages.xsl
xml/chart.xsl
-<?xml version="1.0"?>
-<!--
- | The MIT License
- |
- | Copyright 2014 White Magic Software, Inc.
- |
- | Permission is hereby granted, free of charge, to any person
- | obtaining a copy of this software and associated documentation
- | files (the "Software"), to deal in the Software without
- | restriction, including without limitation the rights to use,
- | copy, modify, merge, publish, distribute, sublicense, and/or
- | sell copies of the Software, and to permit persons to whom the
- | Software is furnished to do so, subject to the following
- | conditions:
- |
- | The above copyright notice and this permission notice shall be
- | included in all copies or substantial portions of the Software.
- |
- | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- | OTHER DEALINGS IN THE SOFTWARE.
- +-->
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-<xsl:include href="math.xsl"/>
-<xsl:include href="colour.xsl"/>
-
-<!-- Pie chart width and height. -->
-<xsl:variable name="width" select="200"/>
-<xsl:variable name="height" select="$width"/>
-
-<xsl:template match="resources">
- <xsl:apply-templates mode="piechart"/>
-</xsl:template>
-
-<xsl:template match="expenses">
- <div class="expenses">
- <xsl:apply-templates mode="piechart"/>
- <xsl:apply-templates select="dataset"/>
- </div>
-</xsl:template>
-
-<xsl:template match="//dataset/*[name()='data' or name()='footer']/value">
- <div class="value"><xsl:value-of
- select="format-number(., '###,###')"/></div>
-</xsl:template>
-
-<!-- Convert XML data into a pie chart. -->
-<xsl:template match="dataset" mode="piechart">
- <!-- Number of wedges. -->
- <xsl:variable name="wedges" select="count(data)"/>
-
- <!-- Calculate the sum of all wedge values. -->
- <xsl:variable name="total" select="sum(data//value)"/>
-
- <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>
- </svg>
- </div>
-
- <!-- SVG 1.1 has no text flow abilities. -->
- <table class="legend" id="legend" name="legend">
- <thead>
- <tr>
- <th colspan="2">Expense</th>
- <th>Amount</th>
- <th></th>
- </tr>
- </thead>
- <tbody>
- <xsl:for-each select="data//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="amount"
- select="format-number(../value, '###,###')"/>
-
- <xsl:variable name="percent"
- select="format-number(../value div $total, '0.00%')"/>
-
- <tr class="wedge">
- <td class="bullet">
- <div class="bullet" style="background-color:{$colour}"/>
- </td>
- <td class="category"><xsl:value-of select="." /></td>
- <td class="amount"><xsl:value-of select="$amount" /></td>
- <td class="percent"><xsl:value-of select="$percent" /></td>
- </tr>
- </xsl:for-each>
- </tbody>
- <tfoot>
- <tr>
- <td></td>
- <td class="total">Total</td>
- <td class="footer">
- <xsl:value-of select="format-number(footer/value, '###,###')"/>
- </td>
- </tr>
- </tfoot>
- </table>
- <div class="legend">
- </div>
- </div>
-</xsl:template>
-
-<!--
- | Creates a pie wedge path.
- |
- | 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">
- <!-- Colour of the pie wedge. -->
- <xsl:param name="colour"/>
- <!-- Sum of all the wedge values. -->
- <xsl:param name="total"/>
- <!-- Sum of all preceding wedge values. -->
- <xsl:param name="runningTotal"/>
- <!-- Pie radius. -->
- <xsl:param name="radius"/>
-
- <!-- Hover text. -->
- <xsl:variable name="title"
- select="concat(../name,' (',format-number(., '###,###'),')')"/>
-
- <!-- 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)"/>
-
- <!-- Calculate the starting Cartesian coordinate. -->
- <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>
- <!-- Calculate the ending Cartesian coordinate. -->
- <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>
-
- <!-- Wedges with angles that exceed 180 degrees must be marked. -->
- <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>
-
- <!-- Ensure the path's d attribute fits on a printed page. -->
- <!-- Note: superfluous variables. -->
- <xsl:variable name="r" select="$radius"/>
- <xsl:variable name="x1r" select="$x1 * $r"/>
- <xsl:variable name="y1r" select="$y1 * $r"/>
- <xsl:variable name="x2r" select="$x2 * $r"/>
- <xsl:variable name="y2r" select="$y2 * $r"/>
-
- <!-- Create the wedge path. -->
- <path xmlns="http://www.w3.org/2000/svg"
- fill="{$colour}"
- title="{$title}"
- stroke="{$stroke_colour}"
- transform="translate({$radius},{$radius})"
- d="M 0 0 L {$x1r} {$y1r} A {$r} {$r} 0 {$sweep} 0 {$x2r} {$y2r} Z"/>
-</xsl:template>
-
-<xsl:template match="title" mode="piechart">
-</xsl:template>
-
-</xsl:stylesheet>
xml/colour.xsl
-<?xml version="1.0"?>
-<!--
- | The MIT License
- |
- | Copyright 2014 White Magic Software, Inc.
- |
- | Permission is hereby granted, free of charge, to any person
- | obtaining a copy of this software and associated documentation
- | files (the "Software"), to deal in the Software without
- | restriction, including without limitation the rights to use,
- | copy, modify, merge, publish, distribute, sublicense, and/or
- | sell copies of the Software, and to permit persons to whom the
- | Software is furnished to do so, subject to the following
- | conditions:
- |
- | The above copyright notice and this permission notice shall be
- | included in all copies or substantial portions of the Software.
- |
- | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- | OTHER DEALINGS IN THE SOFTWARE.
- +-->
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-<!-- Reference white (X, Y, and Z components) -->
-<xsl:variable name="X_r" select="0.950456"/>
-<xsl:variable name="Y_r" select="1.000000"/>
-<xsl:variable name="Z_r" select="1.088754"/>
-<xsl:variable name="LAB_EPSILON" select="216.0 div 24389.0"/>
-<xsl:variable name="LAB_K" select="24389.0 div 27.0"/>
-
-<!-- Pie wedge colours based on this hue. -->
-<xsl:variable name="base_colour" select="'46A5E5'"/>
-
-<!-- Pie wedge stroke colour. -->
-<xsl:variable name="stroke_colour" select="'white'"/>
-
-<!--
- | Creates a colour for a particular pie wedge.
- |
- | http://en.wikipedia.org/wiki/HSL_and_HSV
- +-->
-<xsl:template name="fill">
- <!-- Current wedge number for generating a colour. -->
- <xsl:param name="wedge"/>
- <!-- Total number of wedges in the pie. -->
- <xsl:param name="wedges"/>
- <!-- RGB colour in hexadecimal. -->
- <xsl:param name="colour"/>
-
- <!-- Derive the colour decimal values from $colour's HEX code. -->
- <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>
-
- <!--
- | Convert RGB to XYZ, using nominal range for RGB.
- | http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
- +-->
- <xsl:variable name="r_n" select="$r div 255" />
- <xsl:variable name="g_n" select="$g div 255" />
- <xsl:variable name="b_n" select="$b div 255" />
-
- <!--
- | Assume colours are in sRGB.
- | http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
- -->
- <xsl:variable name="x"
- select=".4124564 * $r_n + .3575761 * $g_n + .1804375 * $b_n"/>
- <xsl:variable name="y"
- select=".2126729 * $r_n + .7151522 * $g_n + .0721750 * $b_n"/>
- <xsl:variable name="z"
- select=".0193339 * $r_n + .1191920 * $g_n + .9503041 * $b_n"/>
-
- <!--
- | Convert XYZ to L*a*b.
- | http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
- +-->
- <xsl:variable name="if_x">
- <xsl:call-template name="lab_f">
- <xsl:with-param name="xyz_n" select="$x div $X_r"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="if_y">
- <xsl:call-template name="lab_f">
- <xsl:with-param name="xyz_n" select="$y div $Y_r"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="if_z">
- <xsl:call-template name="lab_f">
- <xsl:with-param name="xyz_n" select="$z div $Z_r"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="lab_l" select="(116.0 * $if_y) - 16.0"/>
- <xsl:variable name="lab_a" select="500.0 * ($if_x - $if_y)"/>
- <xsl:variable name="lab_b" select="200.0 * ($if_y - $if_z)"/>
-
- <!--
- | Convert L*a*b to LCH.
- | http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
- +-->
- <xsl:variable name="lch_l" select="$lab_l"/>
-
- <xsl:variable name="lch_c">
- <xsl:call-template name="sqrt">
- <xsl:with-param name="n" select="($lab_a * $lab_a) + ($lab_b * $lab_b)"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="lch_h">
- <xsl:call-template name="atan2">
- <xsl:with-param name="x" select="$lab_b"/>
- <xsl:with-param name="y" select="$lab_a"/>
- </xsl:call-template>
- </xsl:variable>
-
- <!--
- | Prevent similar adjacent colours.
- |
- | wi = wedge index number
- | wt = total number of wedges
- | wte = evenness determiniate for wt
- |
- | http://math.stackexchange.com/a/936276/7932
- +-->
- <xsl:variable name="wi" select="$wedge"/>
- <xsl:variable name="wt" select="$wedges"/>
- <xsl:variable name="wtm" select="$wt mod 2"/>
- <xsl:variable name="wte" select="$wt + (1 - $wtm)"/>
-
- <xsl:variable name="w" select="
- round(($wi - $wtm) * floor( $wt div 2 ) mod $wte) + $wtm"/>
-
- <!-- lch_l, lch_c, and lch_h are now set; rotate the hue. -->
- <xsl:variable name="lch_wedge_h" select="(360.0 div $wedges) * $w"/>
-
- <!--
- | Convert wedge's hue-adjusted LCH to L*a*b.
- | http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
- +-->
- <xsl:variable name="lab_sin_h">
- <xsl:call-template name="sine">
- <xsl:with-param name="degrees" select="$lch_wedge_h"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="lab_cos_h">
- <xsl:call-template name="cosine">
- <xsl:with-param name="degrees" select="$lch_wedge_h"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="final_lab_l" select="$lch_l"/>
- <xsl:variable name="final_lab_a" select="$lch_c * $lab_cos_h"/>
- <xsl:variable name="final_lab_b" select="$lch_c * $lab_sin_h"/>
-
- <!--
- | Convert L*a*b to XYZ.
- | http://www.brucelindbloom.com/index.html?Eqn_Lab_to_XYZ.html
- +-->
- <xsl:variable name="of_y" select="($final_lab_l + 16.0) div 116.0"/>
- <xsl:variable name="of_x" select="($final_lab_a div 500.0) + $of_y"/>
- <xsl:variable name="of_z" select="$of_y - ($final_lab_b div 200.0)"/>
-
- <xsl:variable name="of_x_pow">
- <xsl:call-template name="power">
- <xsl:with-param name="base" select="$of_x"/>
- <xsl:with-param name="exponent" select="3"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="of_z_pow">
- <xsl:call-template name="power">
- <xsl:with-param name="base" select="$of_z"/>
- <xsl:with-param name="exponent" select="3"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="ox_r">
- <xsl:choose>
- <xsl:when test="$of_x_pow &gt; $LAB_EPSILON">
- <xsl:value-of select="$of_x_pow"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="((116.0 * $of_x) - 16.0) div $LAB_K"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="oy_r">
- <xsl:choose>
- <xsl:when test="$final_lab_l &gt; ($LAB_K * $LAB_EPSILON)">
- <xsl:call-template name="power">
- <xsl:with-param name="base"
- select="($final_lab_l + 16.0) div 116.0"/>
- <xsl:with-param name="exponent"
- select="3"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$final_lab_l div $LAB_K"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
- <xsl:variable name="oz_r">
- <xsl:choose>
- <xsl:when test="$of_z_pow &gt; $LAB_EPSILON">
- <xsl:value-of select="$of_z_pow"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="((116.0 * $of_z) - 16.0) div $LAB_K"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:variable>
-
- <xsl:variable name="X" select="$ox_r * $X_r"/>
- <xsl:variable name="Y" select="$oy_r * $Y_r"/>
- <xsl:variable name="Z" select="$oz_r * $Z_r"/>
-
- <!--
- | Convert XYZ to sRGB.
- | http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
- +-->
- <xsl:variable name="R"
- select="3.2404542 * $X + -1.5371385 * $Y + -0.4985314 * $Z"/>
- <xsl:variable name="G"
- select="-0.9692660 * $X + 1.8760108 * $Y + 0.0415560 * $Z"/>
- <xsl:variable name="B"
- select="0.0556434 * $X + -0.2040259 * $Y + 1.0572252 * $Z"/>
-
- <!-- Round the result. -->
- <xsl:variable name="R_r" select="round( $R * 255 )"/>
- <xsl:variable name="G_r" select="round( $G * 255 )"/>
- <xsl:variable name="B_r" select="round( $B * 255 )"/>
-
- <xsl:text>rgb(</xsl:text>
- <xsl:value-of select="concat( $R_r, ',', $G_r, ',', $B_r )"/>
- <xsl:text>)</xsl:text>
-</xsl:template>
-
-<xsl:template name="lab_f">
- <xsl:param name="xyz_n"/>
-
- <xsl:choose>
- <xsl:when test="$xyz_n &gt; $LAB_EPSILON">
- <xsl:call-template name="nthroot">
- <xsl:with-param name="index" select="3"/>
- <xsl:with-param name="radicand" select="$xyz_n"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="($LAB_K * $xyz_n + 16.0) div 116.0" />
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Converts a two-digit hexadecimal number to decimal. -->
-<xsl:template name="hex2dec">
- <xsl:param name="hex"/>
-
- <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>
xml/common.xsl
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:include href="chart.xsl"/>
-<xsl:include href="tags.xsl"/>
+<xsl:include href="xsl/chart.xsl"/>
+<xsl:include href="xsl/tags.xsl"/>
<xsl:output
xml/css/votes.css
+.votes {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+
+ float: left;
+ margin-right: 1.5em;
+ color: #A1C436;
+ font-size: 14px;
+}
+
+.votes::before {
+ content: "â–²";
+ padding-bottom: 0.25em;
+}
+
xml/math.xsl
-<?xml version="1.0"?>
-<!--
- | The MIT License
- |
- | Copyright 2014 White Magic Software, Inc.
- |
- | Permission is hereby granted, free of charge, to any person
- | obtaining a copy of this software and associated documentation
- | files (the "Software"), to deal in the Software without
- | restriction, including without limitation the rights to use,
- | copy, modify, merge, publish, distribute, sublicense, and/or
- | sell copies of the Software, and to permit persons to whom the
- | Software is furnished to do so, subject to the following
- | conditions:
- |
- | The above copyright notice and this permission notice shall be
- | included in all copies or substantial portions of the Software.
- |
- | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- | OTHER DEALINGS IN THE SOFTWARE.
- +-->
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-<xsl:variable name="PI">3.14159265358979323846264338327950</xsl:variable>
-<xsl:variable name="PHI">1.61803398874989484820458683436564</xsl:variable>
-<xsl:variable name="PIDIV2" select="$PI div 2.0"/>
-<xsl:variable name="ROOT_PRECISION" select="0.00001"/>
-
-<!-- Calculates square root of n. -->
-<xsl:template name="sqrt">
- <!-- Number to root. -->
- <xsl:param name="n" select="0"/>
- <!-- Used internally. -->
- <xsl:param name="try" select="1"/>
- <!-- Maximum number of iterations (decreases recursively). -->
- <xsl:param name="iter" select="17"/>
-
- <!-- Nate Austin's implementation using Newton's method -->
- <xsl:choose>
- <xsl:when test="($try * $try = $n) or ($iter = 0)">
- <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:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!--
- | Calculates sin(x) as:
- | x(1 - (x^2/2*3)(1 - (x^2/4*5)(1 - (x^2/6*7))))
- | https://www.wolframalpha.com/input/?i=expand+sin(x)
- +-->
-<xsl:template name="sine">
- <!-- Degrees (should be between 0 and 360). -->
- <xsl:param name="degrees"/>
- <!-- Convert degrees to radians when degrees are used. -->
- <xsl:param name="rad" select="$degrees * $PI div 180"/>
- <!-- Maximum number of iterations (decreases recursively). -->
- <xsl:param name="iter" select="31"/>
- <!-- Collects the value of all the terms. -->
- <xsl:param name="result" select="1"/>
-
- <xsl:choose>
- <xsl:when test="$iter &gt; 2">
- <xsl:call-template name="sine">
- <xsl:with-param name="rad" select="$rad"/>
- <xsl:with-param name="iter" select="$iter - 2"/>
- <xsl:with-param name="result"
- select="1 - ((($rad * $rad) div (($iter - 1) * $iter)) * $result)"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise><xsl:value-of select="$rad * $result"/></xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!--
- | Calculates cos(x) as:
- | sine($PIDIV2 - $rad)
- +-->
-<xsl:template name="cosine">
- <!-- Degrees (should be between 0 and 360). -->
- <xsl:param name="degrees"/>
- <!-- Convert degrees to radians when degrees are used. -->
- <xsl:param name="rad" select="$degrees * $PI div 180"/>
- <xsl:call-template name="sine">
- <xsl:with-param name="rad" select="$PIDIV2 - $rad" />
- </xsl:call-template>
-</xsl:template>
-
-<!-- Calculates: 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:choose>
- <xsl:when test="$x = 0.0">
- <xsl:choose>
- <xsl:when test="($y &gt; 0.0)">
- <xsl:value-of select="$PIDIV2"/>
- </xsl:when>
- <xsl:when test="($y &lt; 0.0)">
- <xsl:value-of select="-$PIDIV2"/>
- </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"
- select="($z &gt;= 0) * $z - not($z &gt;= 0) * $z"/>
- <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="$PIDIV2 - ($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"/>
- <xsl:param name="b"/>
-
- <xsl:choose>
- <xsl:when test="$a &gt; $b"><xsl:value-of select="$a"/></xsl:when>
- <xsl:otherwise><xsl:value-of select="$b"/></xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Calculates: radicand^(1/index) -->
-<!-- http://www.shodor.org/unchem/math/newton/ -->
-<xsl:template name="nthroot">
- <xsl:param name="index"/>
- <xsl:param name="radicand"/>
- <!-- Initial guess -->
- <xsl:param name="guess" select="1 + (($radicand - 1) div $index)"/>
-
- <xsl:variable name="approx">
- <xsl:call-template name="nthroot_approx">
- <xsl:with-param name="guess" select="$guess"/>
- <xsl:with-param name="index" select="$index"/>
- <xsl:with-param name="radicand" select="$radicand"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="derivative">
- <xsl:call-template name="nthroot_derivative">
- <xsl:with-param name="guess" select="$guess"/>
- <xsl:with-param name="index" select="$index"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="newGuess" select="$guess - $approx div $derivative"/>
- <xsl:variable name="difference" select="$newGuess - $guess"/>
- <xsl:variable name="precision" select="$guess * $ROOT_PRECISION"/>
-
- <xsl:variable name="abs_difference">
- <xsl:call-template name="abs">
- <xsl:with-param name="x" select="$difference"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:variable name="abs_precision">
- <xsl:call-template name="abs">
- <xsl:with-param name="x" select="$precision"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:choose>
- <xsl:when test="$abs_difference &lt; $abs_precision">
- <xsl:value-of select="$newGuess"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="nthroot">
- <xsl:with-param name="index" select="$index"/>
- <xsl:with-param name="radicand" select="$radicand"/>
- <xsl:with-param name="guess" select="$newGuess"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Calculates: (guess ^ index) - radicand -->
-<xsl:template name="nthroot_approx">
- <xsl:param name="guess"/>
- <xsl:param name="index"/>
- <xsl:param name="radicand"/>
-
- <xsl:variable name="power">
- <xsl:call-template name="power">
- <xsl:with-param name="base" select="$guess"/>
- <xsl:with-param name="exponent" select="$index"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:value-of select="$power - $radicand"/>
-</xsl:template>
-
-<!-- Calculates: index * (guess ^ (index - 1)) -->
-<xsl:template name="nthroot_derivative">
- <xsl:param name="guess"/>
- <xsl:param name="index"/>
-
- <xsl:variable name="power">
- <xsl:call-template name="power">
- <xsl:with-param name="base" select="$guess"/>
- <xsl:with-param name="exponent" select="($index - 1)"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:value-of select="$index * $power"/>
-</xsl:template>
-
-<!-- Calculates: base ^ exponent (whole number exponents) -->
-<xsl:template name="power">
- <xsl:param name="base"/>
- <xsl:param name="exponent"/>
- <xsl:choose>
- <xsl:when test="$exponent = 0">
- <xsl:value-of select="1"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:variable name="t">
- <xsl:call-template name="power">
- <xsl:with-param name="base" select="$base"/>
- <xsl:with-param name="exponent" select="$exponent - 1"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="$base * $t"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Calculates: |x| -->
-<!-- http://en.wikipedia.org/wiki/Absolute_value -->
-<xsl:template name="abs">
- <xsl:param name="x"/>
- <xsl:value-of select="($x &gt;= 0) * $x - not($x &gt;= 0) * $x"/>
-</xsl:template>
-
-</xsl:stylesheet>
xml/pages.xsl
+<?xml version="1.0"?>
+<!--
+ | The MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ |
+ | Permission is hereby granted, free of charge, to any person
+ | obtaining a copy of this software and associated documentation
+ | files (the "Software"), to deal in the Software without
+ | restriction, including without limitation the rights to use,
+ | copy, modify, merge, publish, distribute, sublicense, and/or
+ | sell copies of the Software, and to permit persons to whom the
+ | Software is furnished to do so, subject to the following
+ | conditions:
+ |
+ | The above copyright notice and this permission notice shall be
+ | included in all copies or substantial portions of the Software.
+ |
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ | OTHER DEALINGS IN THE SOFTWARE.
+ +-->
+<xsl:stylesheet version="2.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:strip-space elements="*"/>
+
+<xsl:output method="text"/>
+<xsl:output method="html" indent="yes" name="html" encoding="utf-8"/>
+
+<xsl:template match="/">
+ <xsl:apply-templates />
+</xsl:template>
+
+<xsl:template match="page">
+<xsl:result-document href="{@file}.html" format="html">
+<html>
+<head>
+ <meta charset="utf-8" />
+ <link rel="stylesheet" type="text/css" href="css/tour.css" />
+</head>
+<body>
+<div class="header">
+ <xsl:if test="position() &gt; 1">
+ <a class="page-prev" href="{preceding-sibling::page[1]/@file}.html">Previous</a>
+ </xsl:if>
+ <xsl:if test="position() &lt; last()">
+ <a class="page-next" href="{following-sibling::page[1]/@file}.html">Next</a>
+ </xsl:if>
+</div>
+<hr />
+ <iframe id="page" src="{@file}.xml" width="100%" height="100%" frameborder="0">
+ </iframe>
+</body>
+</html>
+</xsl:result-document>
+</xsl:template>
+
+</xsl:stylesheet>
+
xml/tags.xsl
-<?xml version="1.0"?>
-<!--
- | The MIT License
- |
- | Copyright 2014 White Magic Software, Inc.
- |
- | Permission is hereby granted, free of charge, to any person
- | obtaining a copy of this software and associated documentation
- | files (the "Software"), to deal in the Software without
- | restriction, including without limitation the rights to use,
- | copy, modify, merge, publish, distribute, sublicense, and/or
- | sell copies of the Software, and to permit persons to whom the
- | Software is furnished to do so, subject to the following
- | conditions:
- |
- | The above copyright notice and this permission notice shall be
- | included in all copies or substantial portions of the Software.
- |
- | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- | OTHER DEALINGS IN THE SOFTWARE.
- +-->
-<xsl:stylesheet version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-<!-- Override the match="*" from the common template by forcing priority. -->
-<xsl:template match="taglist" priority="1">
- <div class="columns">
- <ul>
- <xsl:apply-templates mode="tag"/>
- </ul>
- </div>
- <div class="description">
- <h1>Gas</h1>
- <p>
- The <b>gas</b> tag refers to
- <a href="http://en.wikipedia.org/wiki/Natural_gas">natural gas</a>.
- </p>
- </div>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
- <script src="js/columns.js"></script>
-</xsl:template>
-
-<xsl:template match="tag" mode="tag">
-<li>
- <xsl:attribute name="id">
- <xsl:value-of select="@id"/>
- </xsl:attribute>
- <xsl:value-of select="name"/>
- <xsl:if test="tag">
- <ul>
- <xsl:apply-templates select="tag" mode="tag"/>
- </ul>
- </xsl:if>
-</li>
-</xsl:template>
-
-<!-- Ignore any nodes having nothing to do with tags. -->
-<xsl:template match="*" mode="tag"/>
-
-<!-- Ignore the tags not in the correct mode. -->
-<xsl:template match="taglist"/>
-
-</xsl:stylesheet>
xml/template.xsl
-<?xml version="1.0"?>
-<!--
- | The MIT License
- |
- | Copyright 2014 White Magic Software, Inc.
- |
- | Permission is hereby granted, free of charge, to any person
- | obtaining a copy of this software and associated documentation
- | files (the "Software"), to deal in the Software without
- | restriction, including without limitation the rights to use,
- | copy, modify, merge, publish, distribute, sublicense, and/or
- | sell copies of the Software, and to permit persons to whom the
- | Software is furnished to do so, subject to the following
- | conditions:
- |
- | The above copyright notice and this permission notice shall be
- | included in all copies or substantial portions of the Software.
- |
- | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
- | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
- | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
- | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
- | OTHER DEALINGS IN THE SOFTWARE.
- +-->
-<xsl:stylesheet version="2.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-
-<xsl:strip-space elements="*"/>
-
-<xsl:output method="text"/>
-<xsl:output method="html" indent="yes" name="html" encoding="utf-8"/>
-
-<xsl:template match="/">
- <xsl:apply-templates />
-</xsl:template>
-
-<xsl:template match="page">
-<xsl:result-document href="{@file}.html" format="html">
-<html>
-<head>
- <meta charset="utf-8" />
- <link rel="stylesheet" type="text/css" href="css/tour.css" />
-</head>
-<body>
-<div class="header">
- <xsl:if test="position() &gt; 1">
- <a class="page-prev" href="{preceding-sibling::page[1]/@file}.html">Previous</a>
- </xsl:if>
- <xsl:if test="position() &lt; last()">
- <a class="page-next" href="{following-sibling::page[1]/@file}.html">Next</a>
- </xsl:if>
-</div>
-<hr />
- <iframe id="page" src="{@file}.xml" width="100%" height="100%" frameborder="0">
- </iframe>
-</body>
-</html>
-</xsl:result-document>
-</xsl:template>
-
-</xsl:stylesheet>
-
xml/tex/ch-page-proposal.tex
\startsubsection[title={Revise}]
- A rich text editor (such as
- \href{Mercury}{https://github.com/jejacks0n/mercury/tree/mercury2},
- \href{WYSIHTML5}{http://xing.github.io/wysihtml5/},
- \href{hallojs}{http://hallojs.org/},
- \href{AlohaJS}{http://aloha-editor.org/}, or
- \href{redactor}{http://imperavi.com/redactor/}) provides
- a word processing interface for direct content updates.
+ A \href{rich text editor}{https://en.wikipedia.org/wiki/Online_rich-text_editor}
+ provides a word processing interface for direct content updates.
\stopsubsection
xml/xsl/chart.xsl
+<?xml version="1.0"?>
+<!--
+ | The MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ |
+ | Permission is hereby granted, free of charge, to any person
+ | obtaining a copy of this software and associated documentation
+ | files (the "Software"), to deal in the Software without
+ | restriction, including without limitation the rights to use,
+ | copy, modify, merge, publish, distribute, sublicense, and/or
+ | sell copies of the Software, and to permit persons to whom the
+ | Software is furnished to do so, subject to the following
+ | conditions:
+ |
+ | The above copyright notice and this permission notice shall be
+ | included in all copies or substantial portions of the Software.
+ |
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ | OTHER DEALINGS IN THE SOFTWARE.
+ +-->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:include href="math.xsl"/>
+<xsl:include href="colour.xsl"/>
+
+<!-- Pie chart width and height. -->
+<xsl:variable name="width" select="200"/>
+<xsl:variable name="height" select="$width"/>
+
+<xsl:template match="resources">
+ <xsl:apply-templates mode="piechart"/>
+</xsl:template>
+
+<xsl:template match="expenses">
+ <div class="expenses">
+ <xsl:apply-templates mode="piechart"/>
+ <xsl:apply-templates select="dataset"/>
+ </div>
+</xsl:template>
+
+<xsl:template match="//dataset/*[name()='data' or name()='footer']/value">
+ <div class="value"><xsl:value-of
+ select="format-number(., '###,###')"/></div>
+</xsl:template>
+
+<!-- Convert XML data into a pie chart. -->
+<xsl:template match="dataset" mode="piechart">
+ <!-- Number of wedges. -->
+ <xsl:variable name="wedges" select="count(data)"/>
+
+ <!-- Calculate the sum of all wedge values. -->
+ <xsl:variable name="total" select="sum(data//value)"/>
+
+ <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>
+ </svg>
+ </div>
+
+ <!-- SVG 1.1 has no text flow abilities. -->
+ <table class="legend" id="legend" name="legend">
+ <thead>
+ <tr>
+ <th colspan="2">Expense</th>
+ <th>Amount</th>
+ <th></th>
+ </tr>
+ </thead>
+ <tbody>
+ <xsl:for-each select="data//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="amount"
+ select="format-number(../value, '###,###')"/>
+
+ <xsl:variable name="percent"
+ select="format-number(../value div $total, '0.00%')"/>
+
+ <tr class="wedge">
+ <td class="bullet">
+ <div class="bullet" style="background-color:{$colour}"/>
+ </td>
+ <td class="category"><xsl:value-of select="." /></td>
+ <td class="amount"><xsl:value-of select="$amount" /></td>
+ <td class="percent"><xsl:value-of select="$percent" /></td>
+ </tr>
+ </xsl:for-each>
+ </tbody>
+ <tfoot>
+ <tr>
+ <td></td>
+ <td class="total">Total</td>
+ <td class="footer">
+ <xsl:value-of select="format-number(footer/value, '###,###')"/>
+ </td>
+ </tr>
+ </tfoot>
+ </table>
+ <div class="legend">
+ </div>
+ </div>
+</xsl:template>
+
+<!--
+ | Creates a pie wedge path.
+ |
+ | 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">
+ <!-- Colour of the pie wedge. -->
+ <xsl:param name="colour"/>
+ <!-- Sum of all the wedge values. -->
+ <xsl:param name="total"/>
+ <!-- Sum of all preceding wedge values. -->
+ <xsl:param name="runningTotal"/>
+ <!-- Pie radius. -->
+ <xsl:param name="radius"/>
+
+ <!-- Hover text. -->
+ <xsl:variable name="title"
+ select="concat(../name,' (',format-number(., '###,###'),')')"/>
+
+ <!-- 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)"/>
+
+ <!-- Calculate the starting Cartesian coordinate. -->
+ <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>
+ <!-- Calculate the ending Cartesian coordinate. -->
+ <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>
+
+ <!-- Wedges with angles that exceed 180 degrees must be marked. -->
+ <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>
+
+ <!-- Ensure the path's d attribute fits on a printed page. -->
+ <!-- Note: superfluous variables. -->
+ <xsl:variable name="r" select="$radius"/>
+ <xsl:variable name="x1r" select="$x1 * $r"/>
+ <xsl:variable name="y1r" select="$y1 * $r"/>
+ <xsl:variable name="x2r" select="$x2 * $r"/>
+ <xsl:variable name="y2r" select="$y2 * $r"/>
+
+ <!-- Create the wedge path. -->
+ <path xmlns="http://www.w3.org/2000/svg"
+ fill="{$colour}"
+ title="{$title}"
+ stroke="{$stroke_colour}"
+ transform="translate({$radius},{$radius})"
+ d="M 0 0 L {$x1r} {$y1r} A {$r} {$r} 0 {$sweep} 0 {$x2r} {$y2r} Z"/>
+</xsl:template>
+
+<xsl:template match="title" mode="piechart">
+</xsl:template>
+
+</xsl:stylesheet>
xml/xsl/colour.xsl
+<?xml version="1.0"?>
+<!--
+ | The MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ |
+ | Permission is hereby granted, free of charge, to any person
+ | obtaining a copy of this software and associated documentation
+ | files (the "Software"), to deal in the Software without
+ | restriction, including without limitation the rights to use,
+ | copy, modify, merge, publish, distribute, sublicense, and/or
+ | sell copies of the Software, and to permit persons to whom the
+ | Software is furnished to do so, subject to the following
+ | conditions:
+ |
+ | The above copyright notice and this permission notice shall be
+ | included in all copies or substantial portions of the Software.
+ |
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ | OTHER DEALINGS IN THE SOFTWARE.
+ +-->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<!-- Reference white (X, Y, and Z components) -->
+<xsl:variable name="X_r" select="0.950456"/>
+<xsl:variable name="Y_r" select="1.000000"/>
+<xsl:variable name="Z_r" select="1.088754"/>
+<xsl:variable name="LAB_EPSILON" select="216.0 div 24389.0"/>
+<xsl:variable name="LAB_K" select="24389.0 div 27.0"/>
+
+<!-- Pie wedge colours based on this hue. -->
+<xsl:variable name="base_colour" select="'46A5E5'"/>
+
+<!-- Pie wedge stroke colour. -->
+<xsl:variable name="stroke_colour" select="'white'"/>
+
+<!--
+ | Creates a colour for a particular pie wedge.
+ |
+ | http://en.wikipedia.org/wiki/HSL_and_HSV
+ +-->
+<xsl:template name="fill">
+ <!-- Current wedge number for generating a colour. -->
+ <xsl:param name="wedge"/>
+ <!-- Total number of wedges in the pie. -->
+ <xsl:param name="wedges"/>
+ <!-- RGB colour in hexadecimal. -->
+ <xsl:param name="colour"/>
+
+ <!-- Derive the colour decimal values from $colour's HEX code. -->
+ <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>
+
+ <!--
+ | Convert RGB to XYZ, using nominal range for RGB.
+ | http://www.brucelindbloom.com/index.html?Eqn_RGB_to_XYZ.html
+ +-->
+ <xsl:variable name="r_n" select="$r div 255" />
+ <xsl:variable name="g_n" select="$g div 255" />
+ <xsl:variable name="b_n" select="$b div 255" />
+
+ <!--
+ | Assume colours are in sRGB.
+ | http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
+ -->
+ <xsl:variable name="x"
+ select=".4124564 * $r_n + .3575761 * $g_n + .1804375 * $b_n"/>
+ <xsl:variable name="y"
+ select=".2126729 * $r_n + .7151522 * $g_n + .0721750 * $b_n"/>
+ <xsl:variable name="z"
+ select=".0193339 * $r_n + .1191920 * $g_n + .9503041 * $b_n"/>
+
+ <!--
+ | Convert XYZ to L*a*b.
+ | http://www.brucelindbloom.com/index.html?Eqn_XYZ_to_Lab.html
+ +-->
+ <xsl:variable name="if_x">
+ <xsl:call-template name="lab_f">
+ <xsl:with-param name="xyz_n" select="$x div $X_r"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="if_y">
+ <xsl:call-template name="lab_f">
+ <xsl:with-param name="xyz_n" select="$y div $Y_r"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="if_z">
+ <xsl:call-template name="lab_f">
+ <xsl:with-param name="xyz_n" select="$z div $Z_r"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="lab_l" select="(116.0 * $if_y) - 16.0"/>
+ <xsl:variable name="lab_a" select="500.0 * ($if_x - $if_y)"/>
+ <xsl:variable name="lab_b" select="200.0 * ($if_y - $if_z)"/>
+
+ <!--
+ | Convert L*a*b to LCH.
+ | http://www.brucelindbloom.com/index.html?Eqn_Lab_to_LCH.html
+ +-->
+ <xsl:variable name="lch_l" select="$lab_l"/>
+
+ <xsl:variable name="lch_c">
+ <xsl:call-template name="sqrt">
+ <xsl:with-param name="n" select="($lab_a * $lab_a) + ($lab_b * $lab_b)"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="lch_h">
+ <xsl:call-template name="atan2">
+ <xsl:with-param name="x" select="$lab_b"/>
+ <xsl:with-param name="y" select="$lab_a"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <!--
+ | Prevent similar adjacent colours.
+ |
+ | wi = wedge index number
+ | wt = total number of wedges
+ | wte = evenness determiniate for wt
+ |
+ | http://math.stackexchange.com/a/936276/7932
+ +-->
+ <xsl:variable name="wi" select="$wedge"/>
+ <xsl:variable name="wt" select="$wedges"/>
+ <xsl:variable name="wtm" select="$wt mod 2"/>
+ <xsl:variable name="wte" select="$wt + (1 - $wtm)"/>
+
+ <xsl:variable name="w" select="
+ round(($wi - $wtm) * floor( $wt div 2 ) mod $wte) + $wtm"/>
+
+ <!-- lch_l, lch_c, and lch_h are now set; rotate the hue. -->
+ <xsl:variable name="lch_wedge_h" select="(360.0 div $wedges) * $w"/>
+
+ <!--
+ | Convert wedge's hue-adjusted LCH to L*a*b.
+ | http://www.brucelindbloom.com/index.html?Eqn_LCH_to_Lab.html
+ +-->
+ <xsl:variable name="lab_sin_h">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="degrees" select="$lch_wedge_h"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="lab_cos_h">
+ <xsl:call-template name="cosine">
+ <xsl:with-param name="degrees" select="$lch_wedge_h"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="final_lab_l" select="$lch_l"/>
+ <xsl:variable name="final_lab_a" select="$lch_c * $lab_cos_h"/>
+ <xsl:variable name="final_lab_b" select="$lch_c * $lab_sin_h"/>
+
+ <!--
+ | Convert L*a*b to XYZ.
+ | http://www.brucelindbloom.com/index.html?Eqn_Lab_to_XYZ.html
+ +-->
+ <xsl:variable name="of_y" select="($final_lab_l + 16.0) div 116.0"/>
+ <xsl:variable name="of_x" select="($final_lab_a div 500.0) + $of_y"/>
+ <xsl:variable name="of_z" select="$of_y - ($final_lab_b div 200.0)"/>
+
+ <xsl:variable name="of_x_pow">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base" select="$of_x"/>
+ <xsl:with-param name="exponent" select="3"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:variable name="of_z_pow">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base" select="$of_z"/>
+ <xsl:with-param name="exponent" select="3"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="ox_r">
+ <xsl:choose>
+ <xsl:when test="$of_x_pow &gt; $LAB_EPSILON">
+ <xsl:value-of select="$of_x_pow"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="((116.0 * $of_x) - 16.0) div $LAB_K"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="oy_r">
+ <xsl:choose>
+ <xsl:when test="$final_lab_l &gt; ($LAB_K * $LAB_EPSILON)">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base"
+ select="($final_lab_l + 16.0) div 116.0"/>
+ <xsl:with-param name="exponent"
+ select="3"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$final_lab_l div $LAB_K"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="oz_r">
+ <xsl:choose>
+ <xsl:when test="$of_z_pow &gt; $LAB_EPSILON">
+ <xsl:value-of select="$of_z_pow"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="((116.0 * $of_z) - 16.0) div $LAB_K"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+
+ <xsl:variable name="X" select="$ox_r * $X_r"/>
+ <xsl:variable name="Y" select="$oy_r * $Y_r"/>
+ <xsl:variable name="Z" select="$oz_r * $Z_r"/>
+
+ <!--
+ | Convert XYZ to sRGB.
+ | http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html
+ +-->
+ <xsl:variable name="R"
+ select="3.2404542 * $X + -1.5371385 * $Y + -0.4985314 * $Z"/>
+ <xsl:variable name="G"
+ select="-0.9692660 * $X + 1.8760108 * $Y + 0.0415560 * $Z"/>
+ <xsl:variable name="B"
+ select="0.0556434 * $X + -0.2040259 * $Y + 1.0572252 * $Z"/>
+
+ <!-- Round the result. -->
+ <xsl:variable name="R_r" select="round( $R * 255 )"/>
+ <xsl:variable name="G_r" select="round( $G * 255 )"/>
+ <xsl:variable name="B_r" select="round( $B * 255 )"/>
+
+ <xsl:text>rgb(</xsl:text>
+ <xsl:value-of select="concat( $R_r, ',', $G_r, ',', $B_r )"/>
+ <xsl:text>)</xsl:text>
+</xsl:template>
+
+<xsl:template name="lab_f">
+ <xsl:param name="xyz_n"/>
+
+ <xsl:choose>
+ <xsl:when test="$xyz_n &gt; $LAB_EPSILON">
+ <xsl:call-template name="nthroot">
+ <xsl:with-param name="index" select="3"/>
+ <xsl:with-param name="radicand" select="$xyz_n"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="($LAB_K * $xyz_n + 16.0) div 116.0" />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Converts a two-digit hexadecimal number to decimal. -->
+<xsl:template name="hex2dec">
+ <xsl:param name="hex"/>
+
+ <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>
xml/xsl/math.xsl
+<?xml version="1.0"?>
+<!--
+ | The MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ |
+ | Permission is hereby granted, free of charge, to any person
+ | obtaining a copy of this software and associated documentation
+ | files (the "Software"), to deal in the Software without
+ | restriction, including without limitation the rights to use,
+ | copy, modify, merge, publish, distribute, sublicense, and/or
+ | sell copies of the Software, and to permit persons to whom the
+ | Software is furnished to do so, subject to the following
+ | conditions:
+ |
+ | The above copyright notice and this permission notice shall be
+ | included in all copies or substantial portions of the Software.
+ |
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ | OTHER DEALINGS IN THE SOFTWARE.
+ +-->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:variable name="PI">3.14159265358979323846264338327950</xsl:variable>
+<xsl:variable name="PHI">1.61803398874989484820458683436564</xsl:variable>
+<xsl:variable name="PIDIV2" select="$PI div 2.0"/>
+<xsl:variable name="ROOT_PRECISION" select="0.00001"/>
+
+<!-- Calculates square root of n. -->
+<xsl:template name="sqrt">
+ <!-- Number to root. -->
+ <xsl:param name="n" select="0"/>
+ <!-- Used internally. -->
+ <xsl:param name="try" select="1"/>
+ <!-- Maximum number of iterations (decreases recursively). -->
+ <xsl:param name="iter" select="17"/>
+
+ <!-- Nate Austin's implementation using Newton's method -->
+ <xsl:choose>
+ <xsl:when test="($try * $try = $n) or ($iter = 0)">
+ <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:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!--
+ | Calculates sin(x) as:
+ | x(1 - (x^2/2*3)(1 - (x^2/4*5)(1 - (x^2/6*7))))
+ | https://www.wolframalpha.com/input/?i=expand+sin(x)
+ +-->
+<xsl:template name="sine">
+ <!-- Degrees (should be between 0 and 360). -->
+ <xsl:param name="degrees"/>
+ <!-- Convert degrees to radians when degrees are used. -->
+ <xsl:param name="rad" select="$degrees * $PI div 180"/>
+ <!-- Maximum number of iterations (decreases recursively). -->
+ <xsl:param name="iter" select="31"/>
+ <!-- Collects the value of all the terms. -->
+ <xsl:param name="result" select="1"/>
+
+ <xsl:choose>
+ <xsl:when test="$iter &gt; 2">
+ <xsl:call-template name="sine">
+ <xsl:with-param name="rad" select="$rad"/>
+ <xsl:with-param name="iter" select="$iter - 2"/>
+ <xsl:with-param name="result"
+ select="1 - ((($rad * $rad) div (($iter - 1) * $iter)) * $result)"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:otherwise><xsl:value-of select="$rad * $result"/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!--
+ | Calculates cos(x) as:
+ | sine($PIDIV2 - $rad)
+ +-->
+<xsl:template name="cosine">
+ <!-- Degrees (should be between 0 and 360). -->
+ <xsl:param name="degrees"/>
+ <!-- Convert degrees to radians when degrees are used. -->
+ <xsl:param name="rad" select="$degrees * $PI div 180"/>
+ <xsl:call-template name="sine">
+ <xsl:with-param name="rad" select="$PIDIV2 - $rad" />
+ </xsl:call-template>
+</xsl:template>
+
+<!-- Calculates: 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:choose>
+ <xsl:when test="$x = 0.0">
+ <xsl:choose>
+ <xsl:when test="($y &gt; 0.0)">
+ <xsl:value-of select="$PIDIV2"/>
+ </xsl:when>
+ <xsl:when test="($y &lt; 0.0)">
+ <xsl:value-of select="-$PIDIV2"/>
+ </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"
+ select="($z &gt;= 0) * $z - not($z &gt;= 0) * $z"/>
+ <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="$PIDIV2 - ($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"/>
+ <xsl:param name="b"/>
+
+ <xsl:choose>
+ <xsl:when test="$a &gt; $b"><xsl:value-of select="$a"/></xsl:when>
+ <xsl:otherwise><xsl:value-of select="$b"/></xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Calculates: radicand^(1/index) -->
+<!-- http://www.shodor.org/unchem/math/newton/ -->
+<xsl:template name="nthroot">
+ <xsl:param name="index"/>
+ <xsl:param name="radicand"/>
+ <!-- Initial guess -->
+ <xsl:param name="guess" select="1 + (($radicand - 1) div $index)"/>
+
+ <xsl:variable name="approx">
+ <xsl:call-template name="nthroot_approx">
+ <xsl:with-param name="guess" select="$guess"/>
+ <xsl:with-param name="index" select="$index"/>
+ <xsl:with-param name="radicand" select="$radicand"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="derivative">
+ <xsl:call-template name="nthroot_derivative">
+ <xsl:with-param name="guess" select="$guess"/>
+ <xsl:with-param name="index" select="$index"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="newGuess" select="$guess - $approx div $derivative"/>
+ <xsl:variable name="difference" select="$newGuess - $guess"/>
+ <xsl:variable name="precision" select="$guess * $ROOT_PRECISION"/>
+
+ <xsl:variable name="abs_difference">
+ <xsl:call-template name="abs">
+ <xsl:with-param name="x" select="$difference"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:variable name="abs_precision">
+ <xsl:call-template name="abs">
+ <xsl:with-param name="x" select="$precision"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:choose>
+ <xsl:when test="$abs_difference &lt; $abs_precision">
+ <xsl:value-of select="$newGuess"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:call-template name="nthroot">
+ <xsl:with-param name="index" select="$index"/>
+ <xsl:with-param name="radicand" select="$radicand"/>
+ <xsl:with-param name="guess" select="$newGuess"/>
+ </xsl:call-template>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Calculates: (guess ^ index) - radicand -->
+<xsl:template name="nthroot_approx">
+ <xsl:param name="guess"/>
+ <xsl:param name="index"/>
+ <xsl:param name="radicand"/>
+
+ <xsl:variable name="power">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base" select="$guess"/>
+ <xsl:with-param name="exponent" select="$index"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:value-of select="$power - $radicand"/>
+</xsl:template>
+
+<!-- Calculates: index * (guess ^ (index - 1)) -->
+<xsl:template name="nthroot_derivative">
+ <xsl:param name="guess"/>
+ <xsl:param name="index"/>
+
+ <xsl:variable name="power">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base" select="$guess"/>
+ <xsl:with-param name="exponent" select="($index - 1)"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <xsl:value-of select="$index * $power"/>
+</xsl:template>
+
+<!-- Calculates: base ^ exponent (whole number exponents) -->
+<xsl:template name="power">
+ <xsl:param name="base"/>
+ <xsl:param name="exponent"/>
+ <xsl:choose>
+ <xsl:when test="$exponent = 0">
+ <xsl:value-of select="1"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:variable name="t">
+ <xsl:call-template name="power">
+ <xsl:with-param name="base" select="$base"/>
+ <xsl:with-param name="exponent" select="$exponent - 1"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:value-of select="$base * $t"/>
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
+<!-- Calculates: |x| -->
+<!-- http://en.wikipedia.org/wiki/Absolute_value -->
+<xsl:template name="abs">
+ <xsl:param name="x"/>
+ <xsl:value-of select="($x &gt;= 0) * $x - not($x &gt;= 0) * $x"/>
+</xsl:template>
+
+</xsl:stylesheet>
xml/xsl/tags.xsl
+<?xml version="1.0"?>
+<!--
+ | The MIT License
+ |
+ | Copyright 2014 White Magic Software, Inc.
+ |
+ | Permission is hereby granted, free of charge, to any person
+ | obtaining a copy of this software and associated documentation
+ | files (the "Software"), to deal in the Software without
+ | restriction, including without limitation the rights to use,
+ | copy, modify, merge, publish, distribute, sublicense, and/or
+ | sell copies of the Software, and to permit persons to whom the
+ | Software is furnished to do so, subject to the following
+ | conditions:
+ |
+ | The above copyright notice and this permission notice shall be
+ | included in all copies or substantial portions of the Software.
+ |
+ | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ | OTHER DEALINGS IN THE SOFTWARE.
+ +-->
+<xsl:stylesheet version="1.0"
+ xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<!-- Override the match="*" from the common template by forcing priority. -->
+<xsl:template match="taglist" priority="1">
+ <div class="columns">
+ <ul>
+ <xsl:apply-templates mode="tag"/>
+ </ul>
+ </div>
+ <div class="description">
+ <h1>Gas</h1>
+ <p>
+ The <b>gas</b> tag refers to
+ <a href="http://en.wikipedia.org/wiki/Natural_gas">natural gas</a>.
+ </p>
+ </div>
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
+ <script src="js/columns.js"></script>
+</xsl:template>
+
+<xsl:template match="tag" mode="tag">
+<li>
+ <xsl:attribute name="id">
+ <xsl:value-of select="@id"/>
+ </xsl:attribute>
+ <xsl:value-of select="name"/>
+ <xsl:if test="tag">
+ <ul>
+ <xsl:apply-templates select="tag" mode="tag"/>
+ </ul>
+ </xsl:if>
+</li>
+</xsl:template>
+
+<!-- Ignore any nodes having nothing to do with tags. -->
+<xsl:template match="*" mode="tag"/>
+
+<!-- Ignore the tags not in the correct mode. -->
+<xsl:template match="taglist"/>
+
+</xsl:stylesheet>
Delta948 lines added, 936 lines removed, 12-line increase