以文本方式查看主题

-  中文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=8109)


--  作者:greatneal
--  发布时间:6/4/2004 11:46:00 AM

--  [讨论]孤独老师,还是那个数值累计的问题
<引用 标题="[求助]挺困扰人的一个问题,关于数值累计的">
<xsl:variable name='c1><xsl:value-of select="count(客户[(position()=1]/商品信息/商品)"></xsl:variable>
<xsl:variable name='c2'>><xsl:value-of select="count(客户[(position()=2]/商品信息/商品)"></xsl:variable>
<xsl:variable name='c3'>><xsl:value-of select="count(客户[(position()=3]/商品信息/商品)"></xsl:variable>
<xsl:value-of select="$c1+20">
<xsl:value-of select="$c1+20+$c2">
<xsl:value-of select="$c1+20+$c2+$c3">
</引用>

这个方法可以解决我提的问题,不过要是“客户”数量在数据源文件dat.xml中是动态的,可能是3个,也可能是5个,10个。那么我在print.xsl中如何适应变化的数据呢?我总不能dat.xml“客户”数量一变,就改动print.xsl文件中的xsl:variable的个数吧。

麻烦老师教我,谢谢。


--  作者:greatneal
--  发布时间:6/4/2004 11:53:00 AM

--  
javascript脚本或许可以解决这个问题,不过它的命名空间是 xmlns:xsl="http://www.w3.org/TR/WD-xsl",而我用的是xmlns:xsl="http://www.w3.org/1999/XSL/Transform",好像还不太一样,苦恼呀!!!
--  作者:sam
--  发布时间:6/4/2004 1:58:00 PM

--  
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:template match="/">
  <html>
   <head/>
   <body>
    <table border="1">
     <xsl:for-each select="//客户">
      <tr>
       <td>
        <xsl:variable name="num">
         <xsl:call-template name="total">
          <xsl:with-param name="pos" select="position()"/>
         </xsl:call-template>
        </xsl:variable>
        <xsl:value-of select="$num"/>
       </td>
      </tr>
     </xsl:for-each>
    </table>
   </body>
  </html>
 </xsl:template>
 <xsl:template name="total">
  <xsl:param name="pos" select="1"/>
  <xsl:variable name="before">
   <xsl:choose>
    <xsl:when test="$pos >1">
     <xsl:call-template name="total">
      <xsl:with-param name="pos" select="$pos - 1"/>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="this" select="count(//客户[$pos]/商品信息/商品)"/>
  <xsl:value-of select="$this+$before+20"/>
 </xsl:template>
</xsl:stylesheet>

--  作者:greatneal
--  发布时间:6/5/2004 1:42:00 PM

--  
多谢sam兄,好久不用递归了,没想到累积数值会这么麻烦,嘿嘿。
W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms