Sharepoint Xstl全局变量为每个设置并在foreach之后使用
首先,我是XSLT新手。 我正在使用Sharepoint列表,如果有特定季度的数据,我需要获得一个链接来显示。如果某个季度没有数据,我需要有一个这样的标签 因此,我所做的是为给定年份同一月份的每个数据创建一个foreach循环。我知道我无法在xslt中重新分配变量,但我不知道如何做我想要的。 这是我的代码示例。因为我使用Sharepoint,所以我没有访问XML的权限。:/Sharepoint Xstl全局变量为每个设置并在foreach之后使用,sharepoint,xslt,Sharepoint,Xslt,首先,我是XSLT新手。 我正在使用Sharepoint列表,如果有特定季度的数据,我需要获得一个链接来显示。如果某个季度没有数据,我需要有一个这样的标签 因此,我所做的是为给定年份同一月份的每个数据创建一个foreach循环。我知道我无法在xslt中重新分配变量,但我不知道如何做我想要的。 这是我的代码示例。因为我使用Sharepoint,所以我没有访问XML的权限。:/ <xsl:variable name="DataQ1" select="'False'"/> <xsl:
<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>
您在示例代码中使用了
键
函数,但没有发布键的声明。但我认为您可以通过以下代码实现您想要的:
<div>
<xsl:choose>
<xsl:when test="../Row[substring(@Date, 1, 4) = $varYear and substring(@Date, 6, 2) >= 1 and substring(@Date, 6, 2) < 4]">
<a href="http://www.example.com/">LinkToDataofQ1</a>
</xsl:when>
<xsl:otherwise>There's no data for this quarter.</xsl:otherwise>
</xsl:choose>
</div>
没有本季度的数据。
其他一些注意事项:
- 在第1季度的测试中,您编写了
$currentMonth,请编辑问题并提供准确的(最好是小的)源XML文档和转换的准确结果。另外,请解释转换必须实现的要求(规则/约束)。谢谢,这正是我想要的。为我的许多错误感到抱歉。:/很高兴看到你仍然能理解我想要什么!