首先,我是XSLT的新手。 我正在使用Sharepoint列表,如果有特定区域中的数据,我需要获取链接才能显示。如果某个季度没有数据,我需要有一个标签说明。Xstl全局变量设置为每个并在foreach后使用
所以我所做的就是我创建了一个foreach循环,用于给定年份的同一月份的每个数据。我知道我不能在xslt中重新分配一个变量,但我不知道如何执行我想要的操作。 这是我的代码示例。由于我正在使用Sharepoint,因此我没有访问XML。 :/
<xsl:variable name="DataQ1" select="'False'"/>
<xsl:variable name="DataQ2" select="'False'"/>
<xsl:variable name="DataQ3" select="'False'"/>
<xsl:variable name="DataQ4" select="'False'"/>
<xsl:for-each select="../Row[generate-id()=generate-id(key('MonthKey', substring(@Date,6,7))[substring('@Date',1,4) = $varYear)][1])]">
<xsl:variable name="currentMonth" select="number(substring(@Date,6,7))"/>
<xsl:choose>
<xsl:when test="$currentMonth >= 1 and $currentMonth $lt;=4">
<!--set $DataQ1 to true-->
</xsl:when>
<xsl:when test="$currentMonth >= 4 and $currentMonth $lt;=7">
<!--set $DataQ2 to true-->
</xsl:when>
<xsl:when test="$currentMonth >= 7 and $currentMonth $lt;=10">
<!--set $DataQ3 to true-->
</xsl:when>
<xsl:otherwise>
<!--set $DataQ4 to true-->
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
<div>
<xsl:choose>
<xsl:when test="$DataQ1= 'True'">
<a>
<xsl:attribute name="href">
<xsl:value-of select="www.example.come"/>
</xsl:attribute>
<xsl:value-of select="'LinkToDataofQ1'"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="'There's no data for this quarter.'"/>
</xsl:otherwise>
</xsl:choose>
</div>
请编辑问题并提供确切的(最好是小的)源XML文档和确切的转换结果。另外,请说明转换必须执行的要求(规则/限制)。 – 2013-03-27 04:07:53