問如何把一個值放全局參數,下次用時全局參數就是這個值
在XSL中,定義一個全局參數,默認值是0,在使用call-template,把這個全局參數設定一個數值,下一次又調用call-template,全局參數將是上一個數值,不再是默認值,有什麼方法可以實現啊?用XSLT和Xpath來實現。代碼如下:
<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>
<xsl:call-template name="countsf"> <xsl:with-param name="total" select="$total"></xsl:with-param> </xsl:call-template>