以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  [求助]为什么这样就不行了呢?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=13527)


--  作者:hyl_fr
--  发布时间:1/13/2005 9:43:00 AM

--  [求助]为什么这样就不行了呢?
我在用样式表生成饼图的时候,如果中间(不是首尾)有0就会生成错误,后来我为了屏蔽值为0的数据,用了xsl:if,我为每个数据都判断一下是否为0,结果,一个数据也显示不出来了。
      谁能告诉我这是怎么回事啊
--  作者:doubleG
--  发布时间:1/13/2005 11:51:00 AM

--  
???要给点东西出来啊,不然谁都没有办法呢
--  作者:hyl_fr
--  发布时间:1/13/2005 3:22:00 PM

--  
我的xsl:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:VMLObject="http://blueswing.vicp.net" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html"/>
<xsl:variable name="c1" select="format-number(sum(//DataItem/@cwd_amount),'###0.00')"/>
<xsl:variable name="c2" select="format-number(sum(//DataItem/@dep_amount),'###0.00')"/>
<xsl:variable name="c3" select="format-number(sum(//DataItem/@tfr_amount),'###0.00')"/>
<xsl:variable name="c4" select="format-number(sum(//DataItem/@inq_amount),'###0.00')"/>
<xsl:variable name="c5" select="format-number(sum(//DataItem/@pin_amount),'###0.00')"/>
<xsl:variable name="all" select="format-number(sum(//DataItem/@tot_amount),'###0.00')"/>
<xsl:variable name="oth" select="format-number(($all)-($c1+$c2+$c3+$c4+$c5),'###0.00')"/>
<!--这个变量说明以下是饼图(pie)、柱状图(bar)还是曲线(line)-->
<xsl:template match="/">
<table>
<tr><td align="center"><font size="+1"><b>按照交易金额归类比例图</b></font></td></tr>
<tr>
<td>
<center>
<v:group ID="group1" CoordOrig="-3000,-2000" CoordSize="4000,3000" style="width:280;height:210;position:relative">  
  <v:rect style="position:relative;left:-3000;top:-3000;WIDTH:6000;HEIGHT:6000;" fillcolor="white" strokecolor="black">
   <v:shadow on="t" type="single" color="silver" offset="4pt,3pt">
   </v:shadow>
  </v:rect>
  <div id="pie">
  </div>
</v:group>
</center><br></br>
</td>
<td>
<table valign="top" borderColor="black" style="BORDER-COLLAPSE: collapse" border="1" cellpadding="2" cellspacing="0" width="100%"><tr class="listhead" bgColor="#E2EFEA" ><td width="60" align="center">类型</td><td width="80" align="center">数量</td></tr>
  <xsl:if test="c1!='0.00'">
  <tr id="lines"><td id="titles">金额1</td><td id="datas"><xsl:value-of select="$c1"/></td></tr>
  </xsl:if>
  <xsl:if test="c2!='0.00'">
  <tr id="lines"><td id="titles">金额2</td><td id="datas"><xsl:value-of select="$c2"/></td></tr>
  </xsl:if>
  <xsl:if test="c3!='0.00'">
  <tr id="lines"><td id="titles">金额3</td><td id="datas"><xsl:value-of select="$c3"/></td></tr>
  </xsl:if>
  <xsl:if test="oth!='0.00'">
  <tr id="lines"><td id="titles">金额6</td><td id="datas"><xsl:value-of select="$oth"/></td></tr>
  </xsl:if>
  <tr><td align="center">总金额</td><td id="datas"><xsl:value-of select="$all"/></td></tr>
  </table>
</td>
</tr></table>

</xsl:template>
</xsl:stylesheet>


--  作者:doubleG
--  发布时间:1/13/2005 3:51:00 PM

--  
variable变量应该这样去用$...
例如:
<xsl:if test="c1!='0.00'">——><xsl:if test="$c1!='0.00'">
反正这类的都改掉。

--  作者:hyl_fr
--  发布时间:1/13/2005 4:07:00 PM

--  
好,我试试先,谢啦
--  作者:hyl_fr
--  发布时间:1/13/2005 4:15:00 PM

--  
哦,果然是这里啦,再次感谢doubleG!
还有一点小弟不明白,如上xsl如果不判断是否为0,在画饼图的时候,在数值0的地方会出现很奇怪的现象:它占用了下一个数值,但是还是用自己的颜色.
下是我的JSP画饼图的程序:
<%@ taglib uri="/WEB-INF/conf/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/conf/struts-html.tld" prefix="html" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html  xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<script language="javascript">

var r=2000;
//画一个饼图
function createPie(sa,ea,color,n)
{
  var fs=Math.PI*2*(sa/360);
  var fe=Math.PI*2*(ea/360);
  var sx=parseInt(r*Math.sin(fs));
  var sy=parseInt(-r*Math.cos(fs));
  var ex=parseInt(r*Math.sin(fe));
  var ey=parseInt(-r*Math.cos(fe));
  var newPie=document.createElement("<v:shape title='"+n+"' style='position:absolute;z-index:8;width:"+2*r+";height:"+2*r+"' CoordSize='4000,4000' strokeweight='1pt' fillcolor='"+color+"' strokecolor='black' path='m0,0 l "+sx+","+sy+" ar -2000,-2000,2000,2000,"+ex+","+ey+","+sx+","+sy+" l0,0 x e' />");
  pie.insertBefore(newPie);
}
function showPie()
{
  pie.innerHTML="";
  var p=0,n;
  for(i=0;i<document.all.datas.length-1;i++)
  {
   curColor=randomColor();
   n=parseInt(document.all.datas[i].innerText)/parseInt(document.all.datas[document.all.datas.length-1].innerText)*360
   createPie(p,p+n,curColor,document.all.titles[i].innerText);
 document.all.lines[i].bgColor=curColor;
 p=p+n;
  }
}

var curValue=0;
var preColor=0;
var mX=Math.pow(2,16) * 360;
function startAngle(vValue){ 
 var preValue=curValue;
 curValue+=vValue; 
 return parseInt(mX * preValue); 
}

function endAngle(vValue){ 
 return parseInt(mX * vValue);
}

function randomColor(){
 preColor= "rgb("+ parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255) +"," +parseInt( Math.random() * 255)+")";
 return preColor;
}

function curColor(){
 return preColor;
}

//打印
function printPage()
{
 document.all.cmArea.style.posLeft=-1000;
 document.all.cmArea.style.posTop=-1000;
 document.execCommand("print");
 document.all.cmArea.style.posLeft=10;
 document.all.cmArea.style.posTop=10;
}
//显示数据表
function loadTable()
{
 showTable(document.all.xmlfile.value,document.all.tablefile.value);
 document.all.headTitle.innerText=document.all.customerTitle.innerText+document.all.headTitle.innerText;
}
function showTable(xmlfile,xslfile)
{
 // Load XML  
 var xml = new ActiveXObject("Microsoft.XMLDOM") 
 xml.async = false
 xml.load(xmlfile)
 // Load the XSL
 var xsl = new ActiveXObject("Microsoft.XMLDOM")
 xsl.async = false
 xsl.load(xslfile)
 // Transform
  result.innerHTML=xml.transformNode(xsl);
}
var xmlDoc,vmlDoc,VMLFile,XMLFile,VMLType;
function loadVML()
{
 if(xmlDoc==null||vmlDoc==null)
 {
  setTimeout('loadVML()',100);
 }
 else
 {
  var template=new ActiveXObject("MSXML2.XSLTemplate");
  template.stylesheet=vmlDoc;
  var proc=template.createProcessor();
  
  proc.input=xmlDoc;
  proc.transform();
 
  var strResult=proc.output;
  result.innerHTML=strResult;
  if(VMLType=="pie")showPie();
  else if(VMLType=="bar")showBar();
 }
}
function showVML(index)
{
 if(document.all.mapfile.length>0)
 {
  vmlfile=document.all.mapfile[index].value;
  vmltype=document.all.vmlType[index].value;
 }
 else
 {
  vmlfile=document.all.mapfile.value;
  vmltype=document.all.vmlType.value;
 }
 showMap(document.all.xmlfile.value,vmlfile,vmltype);
}
function showMap(xmlfile,vmlfile,vmltype)
{
 XMLFile=xmlfile;
 VMLFile=vmlfile;
 VMLType=vmltype;
 xmlDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument"); 
 xmlDoc.load(XMLFile);
 vmlDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
 vmlDoc.load(VMLFile);
 setTimeout('loadVML()',100);
}
function showHead(xmlfile,xslfile)
{
 // Load XML  
 var xml = new ActiveXObject("MSXML2.FreeThreadedDOMDocument") 
 xml.async = false
 xml.load(xmlfile)
 // Load the XSL
 var xsl = new ActiveXObject("MSXML2.FreeThreadedDOMDocument")
 xsl.async = false
 xsl.load(xslfile);
 var template=new ActiveXObject("MSXML2.XSLTemplate");
 template.stylesheet=xsl;
 var proc=template.createProcessor();
 proc.input=xml;
 proc.transform();
 // Transform
  document.write(proc.output);
}

function drawLinesX(m)
{
count=0; //画横坐标
var textPoint=1;
for(var i=1;i<=10;i++){
    var py=2750-i*245;
    var strTo=m+" "+py;

    var newLine = document.createElement("<v:line from='200 "+py+"' to='"+strTo+"' style='position:absolute;z-index:8'></v:line>");
    group1.insertBefore(newLine);
    if(count%2!=0){
     var newStroke = document.createElement("<v:stroke color='#c0c0c0'>");
     newLine.insertBefore(newStroke); 
        var newShape= document.createElement("<v:shape style='position:absolute;left:-350;top:"+(py-50)+";WIDTH:1000px;HEIGHT:200px;z-index:8' coordsize='21600,21600' fillcolor='white'></v:shape>")    
        group1.insertBefore(newShape);        
        var newText = document.createElement("<v:textbox id='tx"+textPoint+"' inset='3pt,0pt,3pt,0pt' style='font-size:10pt;v-text-anchor:bottom-right-baseline'></v:textbox>");
        newShape.insertBefore(newText);
        newText.innerText=textPoint;
        textPoint++;
 }
 else
 {
     var newStroke = document.createElement("<v:stroke dashstyle='dot' color='black'/>");
     newLine.insertBefore(newStroke);
 }
 count++;
}
}
function drawLinesY(n)
{
var textPoint=1;
for(var i=1;i<=n;i++){
    var py=170+i*300;
    var newLine = document.createElement("<v:line from='"+py+" 2700' to='"+py+" 2750' style='position:absolute;z-index:8'></v:line>");
    group1.insertBefore(newLine);
    var newStroke = document.createElement("<v:stroke color='black'>");
    newLine.insertBefore(newStroke); 
    var newShape= document.createElement("<v:shape style='position:absolute;left:"+(py-50)+";top:2750;WIDTH:200px;HEIGHT:150px;z-index:8' coordsize='21600,21600' fillcolor='white'></v:shape>")    
    group1.insertBefore(newShape);        
    var newText = document.createElement("<v:textbox id='ty"+textPoint+"' inset='3pt,0pt,3pt,0pt' style='font-size:9pt;v-text-anchor:bottom-right-baseline'></v:textbox>");
    newShape.insertBefore(newText);
 newText.innerHTML=textPoint;
    textPoint++;
}
}
function drawBar(v,t,c)
{
  var h=v*245-50;
  var px=2750-v*245;
  var py=170+t*300;
  var newShape= document.createElement("<v:rect style='position:absolute;left:"+py+";top:"+px+";WIDTH:190px;HEIGHT:"+h+"px;z-index:9' coordsize='21600,21600' fillcolor='"+c+"'></v:rect>")    
  group1.insertBefore(newShape);
}
function showBar()
{
  drawLinesX(4500);
  drawLinesY(13);
  for(i=0;i<document.all.datas.length-1;i++)
  {
   curColor=randomColor();
   n=parseInt(document.all.datas[i].innerText)/parseInt(document.all.datas[document.all.datas.length-1].innerText);
 n=(n+0.5)*5;
// alert(n+","+(i+1));
 drawBar(n,i+1,curColor);
 document.all.lines[i].bgColor=curColor;
  }
}

</script>

<script src="../share/coolbuttons.js" language="JavaScript"></script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title><bean:message key="atmv.title"/></title>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ page import="com.longtop.commons.tools.*"%>
<%@ page import="java.io.*"%>
<%
  //XML
  String XMLfile=(String)request.getAttribute("XMLfilename");
  String XSLfile=(String)request.getAttribute("XSLfilename");
  String rootPath = request.getContextPath();
  String resultStart="<div id='result' style=\"position:absolute; left:10px; top:50px; z-index:0 \">";
  String divEnd="</div>";  
  String headStart="<div id=\"cmArea\" style=\"position:absolute; left:10px; top:10px; z-index:0 \">";
%>
<link rel="stylesheet" href="/share/style.css" type="text/css">
<STYLE>
v\:* { BEHAVIOR: url(#default#VML) }
</STYLE>
</head>
<body topmargin="0">
 <%
  if(XMLfile==null||XSLfile==null)
  {
   out.println(headStart);
 %>   
   <table width="100%">
   <tr>
   <td id=Td_print title='打印'>
    <TABLE  border=0 cellpadding=0 cellspacing=0>
    <TBODY>
    <TR>
     <TD class=btntdbmp noWrap align=middle>
     <SPAN onclick=printPage() class=coolButton style='WIDTH: 100px'>
     <table id=dispTable border=0 cellpadding=0 cellspacing=0>
     <tr>
     <td>
       <IMG height=16 src='../images/icon_print.gif' width=16 align=absBottom>
     </td>
     <td>
       打印报表
     </td>
     </tr>
     </table>
     </SPAN>
     </TD>
    </TR>
    </TBODY>
    </TABLE>
   </td>
   </tr>
   <tr><td height="20">&nbsp;</td></tr>
   </table>
 <%
   out.println(divEnd);
   out.println(resultStart);
   String filepath = (String)request.getAttribute("strFilePath");
   java.io.LineNumberReader br = new java.io.LineNumberReader(new java.io.FileReader(filepath));
 
   String fileline = "";
   PubTools tool = new PubTools();
   //PageDisplay pagedis = new PageDisplay();
   int ii = 0;
   int len=1;
   while(fileline != null)
   {
    fileline = br.readLine();
    fileline = EncodingFilter.getStrFromFile(fileline);
    if(fileline==null)break;
    out.println(fileline);
    ii++;
   }
   new File(filepath).delete();
   out.println(divEnd);
 }
 else
 {
//   out.println(headStart+divEnd);//菜单
   out.println("<input name='xmlfile' type='hidden' value='/temp/"+XMLfile+"'>");
   out.println("<input name='xslfile' type='hidden' value='/Templates/"+XSLfile+"'>");   
   out.println("<script>");
   out.println("showHead('/Templates/default.xml','/Templates/"+XSLfile+"');");
   out.println("showTable('/temp/"+XMLfile+"',document.all.tablefile.value);");
   out.println("document.all.headTitle.innerText=document.all.customerTitle.innerText+document.all.headTitle.innerText;");
   out.println("</script>");
 }
 %>
</body>
</html>


--  作者:hyl_fr
--  发布时间:1/13/2005 4:23:00 PM

--  

类型 数量
笔数1 380
笔数2 0
笔数3 322
笔数4 410
笔数5 362
笔数6 370
总笔数 1844
结果画出来的是5块,但是没有笔数1,笔数2占了1的数值,但是颜色还是笔数2的


--  作者:doubleG
--  发布时间:1/13/2005 4:44:00 PM

--  
好长的程序阿,看不下去呢,呵呵。程序在我这里也没办法运行,我也很难说清是怎么回事呢。我瞎猜吧,可能是这样,如果你不加这个判断,那么它就会生成一个元素就是你的<tr><td>...这个,但是0在统计图中是没有它的位置的,但是你的程序可能只是按照声称的元素来分配颜色的吧,但是碰到0它又跳了过去,这样就出现了你那个情况。但是你加了判断就不出现那个元素了,那么就正常的喽。臆断而已 ,呵呵。
--  作者:hyl_fr
--  发布时间:1/13/2005 5:00:00 PM

--  
呵呵,我猜想也是这个原因,所以才想加上判断,只是这样虽然解决了那个问题,但是,页面上就没有值为0的字段的信息了。我是初涉xml,很多还是模仿写出的,应该严重充电。
--  作者:doubleG
--  发布时间:1/13/2005 5:15:00 PM

--  
开始都要模仿啊,时间长了就有自己的体会了,呵呵
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
109.375ms