---
title: "XSL循环 1~X(X为指定变量的值或固定值)"
author: "qsrock"
date: "2008-05-06T09:33:07Z"
tags: ["Java", "XSL"]
slug: "xsl-1-x-x"
draft: false
lastmod: "2008-05-06T09:33:07Z"
id: 190004
url: "https://qsrock.iteye.com/blog/190004"
---

我这里是循环一个月的数据

```java
<!--days是每个月的天数-->
<xsl:variable name="days">
    <xsl:value-of select="/root/row[1]/@days" />
</xsl:variable>

<xsl:call-template name="loop">
	<xsl:with-param name="i" select="1" /> 
	<xsl:with-param name="maxCount" select="$days" />
</xsl:call-template>

<xsl:template name="loop">
	<xsl:param name="i" select="0" />
	<xsl:param name="maxCount" select="0" />
		<xsl:value-of select="$i" />, 
		<xsl:param name="tempvalue" select="format-number(sum(/root/row/@*[substring-after(name(.), 'gather')=$i]),'########0')"  />
<!--这里是要留意的，/root/row/@*[substring-after(name(.), 'gather')=$i]),表示"/root/row/Gather"后面加 1~X 即/root/row/Gather1,/root/row/Gather2,/root/row/Gather3,...,/root/row/GatherX-->
		<xsl:value-of select="$tempvalue" />,
		<!--xsl:value-of select="./@*[$i+16]" /-->
	
	<xsl:if test="$i &lt; $maxCount">
	    <xsl:call-template name="loop">
		<xsl:with-param name="i" select="$i+1" />
		<xsl:with-param name="maxCount" select="$maxCount" />
	    </xsl:call-template>
	</xsl:if>
</xsl:template>
```