<!--                                                                  -->
<!--  Copyright (C) 2006 RoyaltyShare, Inc.   All Rights Reserved     -->
<!--  $Id$  -->
<!--                                                                  -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <!-- useful little function-like templates that we use throughout the site -->

    <xsl:template name="escapeJavascript">
        <xsl:param name="string" />
        <xsl:choose>
            <xsl:when test='contains($string, "&apos;")'>
                <xsl:call-template name="escapeJavascript">
                    <xsl:with-param name="string" select='substring-before($string, "&apos;")' />
                </xsl:call-template>
                <xsl:text>\'</xsl:text>
                <xsl:call-template name="escapeJavascript">
                    <xsl:with-param name="string" select='substring-after($string, "&apos;")' />
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="contains($string, '&#xA;')">
                <xsl:call-template name="escapeJavascript">
                    <xsl:with-param name="string" select="substring-before($string, '&#xA;')" />
                </xsl:call-template>
                <xsl:text>\n</xsl:text>
                <xsl:call-template name="escapeJavascript">
                    <xsl:with-param name="string" select="substring-after($string, '&#xA;')" />
                </xsl:call-template>
            </xsl:when>
            <xsl:when test="contains($string, '\')">
                <xsl:value-of select="substring-before($string, '\')" />
                <xsl:text>\\</xsl:text>
                <xsl:call-template name="escapeJavascript">
                    <xsl:with-param name="string" select="substring-after($string, '\')" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="fixQuotes">
        <xsl:param name="string"/>
        <xsl:choose>
            <xsl:when test="contains($string, &quot;'&quot;)">
                <xsl:value-of select="substring-before($string, &quot;'&quot;)"/>
                <xsl:text>\'</xsl:text>
                <xsl:call-template name="fixQuotes">
                    <xsl:with-param name="string" select="substring-after($string, &quot;'&quot;)"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$string"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="formatDollars">
        <xsl:param name="dollarAmount" />

        <xsl:value-of select="$dollarAmount" />

    </xsl:template>


    <xsl:template name="formatNumber">
        <xsl:param name="number" />

        <xsl:value-of select="$number" />

    </xsl:template>

    <xsl:template name="replaceDash">
        <xsl:param name="string" />
        <xsl:value-of select="translate($string,'-','&#8209;')" />
    </xsl:template>

    <xsl:template name="replaceLineBreak">
        <xsl:param name="string"/>
        <xsl:choose>
            <xsl:when test="contains($string,'&#10;')">
                <xsl:value-of select="substring-before($string,'&#10;')"/>
                <br/>
                <xsl:call-template name="replaceLineBreak">
                    <xsl:with-param name="string" select="substring-after($string,'&#10;')"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$string"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>


    <xsl:template name="pieSectionTip">
        <xsl:param name="value" />

        <xsl:variable name="formattedLegendValue">
            <xsl:call-template name="formatDollars">
                <xsl:with-param name="dollarAmount" select="$value" />
            </xsl:call-template>
        </xsl:variable>

        <xsl:value-of select="Label" />
        <xsl:text> &#x2014; </xsl:text>
        <xsl:value-of select="Percent" />
        <xsl:text>&lt;br&gt;</xsl:text>
        <xsl:value-of select="$formattedLegendValue" />
    </xsl:template>

</xsl:stylesheet>

