-- 作者:leomay
-- 发布时间:6/11/2005 2:32:00 PM
-- 各位高手清出招(在线等)无法正常显示直方图qq:383743748 msn:leomayleomay@hotmail.com
XSL文件 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" encoding="UTF-8" version="1.0" standalone="no" media-type="image/svg+xml"/> <xsl:variable name="bar_width" select="number(80)"/> <xsl:variable name="bar_spacing" select="number(10)"/> <xsl:variable name="graph_height" select="number(500)"/> <xsl:variable name="left_margin" select="number(100)"/> <xsl:template match="/"> <svg id="body" viewBox="0 0 -100 {$graph_height + 100}"> <script type="text/ECMAScript"> <![CDATA[ function On_MouseOver(evt,HideShow_ID){ var target = evt.getTarget(); var doc = target.getOwnerDocument(); var HideShow = doc.getElementById(HideShow_ID); HideShow.setAttribute('style', 'visibility:visible'); } function On_MouseOut(evt,HideShow_ID){ var target = evt.getTarget(); var doc = target.getOwnerDocument(); var HideShow = doc.getElementById(HideShow_ID); HideShow.setAttribute('style', 'visibility:hidden'); } ]]> </script> <title>BarChart</title> <g id="barChart" transform="translate(10, 10)" fill-rule="nonzero" clip-rule="nonzero" stroke="none" class="legend" stroke-width="1" stroke-linecap="square" stroke-miterlimit="1" style="text-anchor:start" shape-rendering="crispEdges"> <xsl:apply-templates select="sales_summary"/> <text text-anchor="middle" transform="matrix(2 0 0 2{$left_margin + 150} {$graph_height + 70})">Month Sale Record of the company</text> </g> </svg> </xsl:template> <xsl:template match="sales_summary"> <xsl:variable name="weeks_count" select="count(Month_sales)"/> <xsl:variable name="max_week_sales_value"> <xsl:for-each select="Month_sales"> <xsl:sort select="sum(product_sales/@value)" data-type="number" order="descending"/> <xsl:if test="position() = 1"> <xsl:value-of select="sum(product_sales/@value)"/> </xsl:if> </xsl:for-each> </xsl:variable> <xsl:variable name="max_graph_height" select="floor(($max_week_sales_value + 99) div 100) * 100"/> <xsl:call-template name="draw_graph"> <xsl:with-param name="max_graph_height" select="$max_graph_height"/> <xsl:with-param name="bar_count" select="$weeks_count"/> </xsl:call-template> <xsl:apply-templates select="Month_sales"> <xsl:sort select="Month_sales/@Month_no" data-type="number"/> <xsl:with-param name="max_graph_height" select="$max_graph_height"/> </xsl:apply-templates> </xsl:template> <xsl:template name="draw_graph"> <xsl:param name="max_graph_height"/> <xsl:param name="bar_count"/> <xsl:variable name="actual_width" select="($bar_count * ($bar_width + $bar_spacing)) + $bar_spacing"/> <g id="GridAndLegend" style="stroke:#00FF00;" shape-rendering="crispEdges" stroke-width="1"> <path fill="rgb(255, 235, 205)" stroke="#000099" d="M {$left_margin},{$graph_height + 20} h{$actual_width} v-{$graph_height + 10} h-{$actual_width} v{$graph_height +10}"/> <path fill="none" stroke="#FF0000" d="M {$left_margin - 10},{$graph_height + 20} h10"/> <text text-anchor="end" baseline-shift="-3" transform="matrix(1 0 0 1 {$left_margin - 15} {$graph_height + 20})">0</text> <xsl:call-template name="draw_graph_vertical_legends"> <xsl:with-param name="max" select="$max_graph_height"/> <xsl:with-param name="legend_threshold" select="$max_graph_height div $graph_height"/> <xsl:with-param name="actual_width" select="$actual_width"/> </xsl:call-template> </g> </xsl:template> <xsl:template name="draw_graph_vertical_legends"> <xsl:param name="max"/> <xsl:param name="legend_threshold"/> <xsl:param name="actual_width"/> <xsl:param name="start" select="number(100)"/> <xsl:param name="step" select="number(100)"/> <xsl:param name="prev_marked_start" select="number(0)"/> <xsl:variable name="prev_vert_posn" select="($prev_marked_start div $max) * $graph_height"/> <xsl:variable name="vert_posn" select="($start div $max) * $graph_height"/> <xsl:variable name="new_marked_start"> <xsl:choose> <xsl:when test="($vert_posn - $prev_vert_posn) >= $legend_threshold"> <xsl:value-of select="$start"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$prev_marked_start"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:if test="$new_marked_start = $start"> <path fill="none" stroke="#FF0000" d="M {$left_margin - 10},{$graph_height + 20 - floor($vert_posn)} h{$actual_width + 10}"/> <text text-anchor="end" baseline-shift="-3" transform="matrix(1 0 0 1 {$left_margin - 15} {$graph_height + 20 - floor($vert_posn)})"> <xsl:value-of select="$start"/> </text> </xsl:if> <xsl:if test="$start < $max"> <xsl:call-template name="draw_graph_vertical_legends"> <xsl:with-param name="max" select="$max"/> <xsl:with-param name="legend_threshold" select="$legend_threshold"/> <xsl:with-param name="actual_width" select="$actual_width"/> <xsl:with-param name="start" select="$start + $step"/> <xsl:with-param name="step" select="$step"/> <xsl:with-param name="prev_marked_start" select="$new_marked_start"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template match="Month_sales"> <xsl:param name="max_graph_height"/> <xsl:variable name="sales_value" select="sum(product_sales/@value)"/> <xsl:variable name="bar_height" select="floor(($sales_value div $max_graph_height) * $graph_height)"/> <xsl:variable name="bar_left" select="((position() - 1) * ($bar_width + $bar_spacing)) + $bar_spacing"/> <path fill="#0066FF" stroke="none" d="M {$bar_left + $left_margin},{$graph_height + 19} h{$bar_width} v-{$bar_height} h-{$bar_width} v{$bar_height}" onmouseover="On_MouseOver(evt,'HideShow_{Month_sales/@Month_no}')" onmouseout="On_MouseOut(evt,'HideShow_{Month_sales/@Month_no}')"/> <text text-anchor="middle" transform="matrix(1.5 0 0 1.5 {$left_margin + $bar_left + ($bar_width div 2)} {$graph_height + 40})"> <xsl:value-of select="Month_sales/@Month_no"/> <xsl:text>Month</xsl:text> </text> <g id="HideShow_{Month_sales/@Month_no}" style="visibility: hidden;"> <path fill="none" stroke="red" d="M {$left_margin - 10},{$graph_height + 20 - $bar_height} h{$bar_left + 10}"/> <text transform="matrix(1 0 0 1 {$left_margin + $bar_left + 2} {($graph_height + 30) - $bar_height})"> <xsl:value-of select="format-number($sales_value,'#,##0')"/> </text> </g> </xsl:template> </xsl:stylesheet> xml文件 <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="C:\Inetpub\wwwroot\XSLTToGraph.xsl"?> <sales_summary> <Month_sales Month_no="1"> <product_sales product_id="PC_INTEL_001" quantity="5" value="5000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="1500.00"/> </Month_sales> <Month_sales Month_no="2"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="3"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="4"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="5"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="6"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="7"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="8"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="9"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="10"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="11"> <product_sales product_id="PC_INTEL_001" quantity="4" value="4000.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="3000.00"/> <product_sales product_id="PC_AMD_001" quantity="20" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="20" value="1800.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="11" value="50.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="18" value="600.00"/> </Month_sales> <Month_sales Month_no="12"> <product_sales product_id="PC_INTEL_001" quantity="56" value="200.00"/> <product_sales product_id="PC_INTEL_002" quantity="10" value="500.00"/> <product_sales product_id="PC_AMD_001" quantity="61" value="1500.00"/> <product_sales product_id="PC_AMD_002" quantity="8" value="2100.00"/> <product_sales product_id="PC_DIGITAL_001" quantity="2" value="500.00"/> <product_sales product_id="PC_DIGITAL_002" quantity="6" value="1200.00"/> </Month_sales> </sales_summary> 无法正常显示直方图
|