读书人

怎么把一值放全局下次用全

发布时间: 2012-04-06 12:22:24 作者: rapoo

如何把一值放全局,下次用全局就是值
在XSL中,定一全局,默值是0,在使用call-template,把全局定一值,下一次又用call-template,全局是上一值,不再是默值,有什方法可以啊?用XSLT和Xpath。代如下:

XML code
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cmp=" http://www.bolero.net/io/xmlns/header/1.0" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:test="anything here">  <xsl:output encoding="utf-8" omit-xml-declaration="no" indent="no" version="1.0" standalone="no"/>  <xsl:param name="total" select="0"/>    <xsl:template name="aa" match="/">      <html xmlns="http://www.w3.org/1999/xhtml">    <head>    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>    <title>test</title>    </head>    <body>    <table border="1" width="600">      <tr>    <td><xsl:call-template name="countsf">              <xsl:with-param name="total" select="$total"></xsl:with-param>                          </xsl:call-template></td>          <td><xsl:call-template name="countsf">           <xsl:with-param name="total" select="$total"></xsl:with-param>                              </xsl:call-template></td>      </tr>    </table>    </body>    </html>  </xsl:template>   <xsl:template name="countsf">     <xsl:param name="total" select="$total"></xsl:param>     <xsl:param name="i">1</xsl:param>     <xsl:value-of select="$total"></xsl:value-of>     <xsl:text>/</xsl:text>     <xsl:if test="$i < 2">            <xsl:call-template name="countsf">                 <xsl:with-param name="total" select="$total + 1"></xsl:with-param>                 <xsl:with-param name="i" select="$i + 1"></xsl:with-param>            </xsl:call-template>     </xsl:if>     </xsl:template></xsl:stylesheet>


就是total累加,出次
XML code
<xsl:call-template name="countsf">           <xsl:with-param name="total" select="$total"></xsl:with-param>                              </xsl:call-template>
,total就等於次。

[解决办法]

读书人网 >XML SOAP

热点推荐