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:
<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[substring-before(substring-after(@Nominee, '?ID='), '"') = substring-before(substring-after(current()/@Nominee, '?ID='), '"')]/@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='), '"')), 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[substring-before(substring-after(@Nominee, '?ID='), '"') = substring-before(substring-after(current()/@Nominee, '?ID='), '"')]/@Amount)"/> <xsl:variable name="HistWidth" select="500" /> <xsl:variable name="ThisBarValue" select="sum($Rows[substring-before(substring-after(@Nominee, '?ID='), '"') = substring-before(substring-after(current()/@Nominee, '?ID='), '"')]/@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"><![CDATA[ ]]></xsl:text> </tr> </table> </td> </tr> </xsl:if> </xsl:template>
One Comment