Skip to content

Instantly share code, notes, and snippets.

@creativedutchmen
Created July 1, 2012 13:33
Show Gist options
  • Save creativedutchmen/3028437 to your computer and use it in GitHub Desktop.
Save creativedutchmen/3028437 to your computer and use it in GitHub Desktop.
<data>
<entry id="1">
<event>First Game</event>
<odds>1.2</odds>
<outcome>Win</outcome>
</entry>
<entry id="2">
<event>Second Game</event>
<odds>1.8</odds>
<outcome>Win</outcome>
</entry>
<entry id="3">
<event>Third Game</event>
<odds>1.75</odds>
<outcome>Win</outcome>
</entry>
<entry id="4">
<event>Fourth Game</event>
<odds>2</odds>
<outcome>Loss</outcome>
</entry>
<entry id="5">
<event>Fifth Game</event>
<odds>1.15</odds>
<outcome>Win</outcome>
</entry>
</data>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:variable name="count" select="count(/data/entry)"/>
<xsl:template match="/data/entry">
<xsl:param name="total" select="0"/>
<xsl:param name="price" select="0"/>
<xsl:variable name="new-total">
<xsl:choose>
<xsl:when test="outcome = 'Win'">
<xsl:value-of select="$total + ($price * odds)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$total - ($price)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="not(./following-sibling::entry)">
<xsl:value-of select="$new-total"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="./following-sibling::entry[1]">
<xsl:with-param name="total" select="$new-total"/>
<xsl:with-param name="price" select="$price"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="/">
<xsl:apply-templates select="/data/entry[position() = 1]">
<xsl:with-param name="price" select="100"/>
</xsl:apply-templates>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment