Showing Subtotals in a DVWP, Sorted by the Subtotals – Part 3

UltraGC is putting me through my DVWP paces with follow on questions on this topic, but I’m having fun figuring out each additional piece.  In parts one and two, I showed how to sum the values by a text column, and then for each person in a Person/Group column.  So what if you’d like to display a histogram for each of the values in my previous examples?  You could pretty easily do this by using the relative values as the width of an embedded <table> with a background.  Here I’ve added a new <table> which displays the corresponding bars for the values, which looks like this:

image

<xsl:template name="dvt_1.body">
    <xsl:param name="Rows"/>
    <xsl:variable name="MaxHistWidth" select="sum($Rows/@Amount)"/>
    <xsl:for-each select="$Rows">
        <xsl:sort select="sum($Rows&#91;substring-before(substring-after(@Nominee, '?ID='), '&quot;') =
            substring-before(substring-after(current()/@Nominee, '?ID='), '&quot;')&#93;/@Amount)" data-type="number" order="descending" />
        <xsl:call-template name="dvt_1.rowview">
            <xsl:with-param name="Rows" select="$Rows"/>
            <xsl:with-param name="MaxHistWidth" select="$MaxHistWidth"/>
        </xsl:call-template>
    </xsl:for-each>
</xsl:template>
<xsl:template name="dvt_1.rowview">
    <xsl:param name="Rows"/>
    <xsl:param name="MaxHistWidth"/>
    <xsl:variable name="NewUserID" select="ddwrt:NameChanged(string(substring-before(substring-after(@Nominee, '?ID='), '&quot;')), 0)"/> 
    <xsl:if test="string-length($NewUserID) > 0">
       
<tr>
           
<td class="ms-vb">
                <xsl:value-of select="@Nominee" disable-output-escaping="yes"/>
           </td>
           
<td class="ms-vb">
                <xsl:value-of select="sum($Rows&#91;substring-before(substring-after(@Nominee, '?ID='), '&quot;') =
                    substring-before(substring-after(current()/@Nominee, '?ID='), '&quot;')&#93;/@Amount)"/>
                <xsl:variable name="HistWidth" select="500" />
                <xsl:variable name="ThisBarValue" select="sum($Rows&#91;substring-before(substring-after(@Nominee, '?ID='), '&quot;') =
                    substring-before(substring-after(current()/@Nominee, '?ID='), '&quot;')&#93;/@Amount)"/>
                <xsl:variable name="ThisBarWidth" select="($ThisBarValue div $MaxHistWidth) * $HistWidth"/>
               
<table cellpadding="0" cellspacing="0" border="0" width="{round($ThisBarWidth)}px;">
                   
<tr bgcolor="blue">
                        <xsl:text disable-output-escaping="yes"><!&#91;CDATA&#91;&nbsp;&#93;&#93;></xsl:text>
                   </tr>
               </table>
           </td>
       </tr>
    </xsl:if>
</xsl:template>

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.