我遇到了尝试按日期过滤SharePoint列表的实际问题。我想列出一个月/年的列表,其中每个条目都有一个来自列表的计数,其中计数包括大于或等于该月的第15日或小于下一个月的第15日的日期。我可以在12月份以外的任何月份都做到这一点,我希望计数从2009年12月15日到2010年1月14日(例如)。我真的不明白为什么应该有什么区别,因为我使用相同的方法。如果任何人都可以在我的代码中看到错误,或者有更好的方法,我会非常感激。Sharepoint日期操作和过滤
<xsl:template name="generateTable">
<xsl:param name="numMonths" />
<xsl:param name="Rows" />
<xsl:param name="dvt_Rows" />
<xsl:param name="tday" select="$startDay" />
<xsl:param name="tmonth" select="($startMonth + msxsl:node-set($numMonths)-1) mod 12 + 1" />
<xsl:param name="tyear" select="$startYear + floor(($numMonths+msxsl:node-set($startMonth)-1) div 12)" />
<xsl:variable name="date" select="concat($tday,'/',$tmonth,'/',$tyear)"/>
<tr>
<td>
<xsl:value-of select="ddwrt:FormatDateTime(string($date),3081,'MMMM yyyy')"/>
</td>
<td>
<xsl:choose>
<xsl:when test="$tmonth=12">
<xsl:value-of select="count(/dsQueryResponse/Rows[1]/Row[(
(ddwrt:FormatDateTime (string (@Date) , 3081, 'M yyyy'))=(ddwrt:FormatDateTime (string ($date) , 3081, 'M yyyy'))
and number(substring(ddwrt:FormatDateTime(string(@Date), 3081, 'dd'),1,2)) >=$startDay)])+
count(/dsQueryResponse/Rows[1]/Row[(
concat(string(number(substring(ddwrt:FormatDateTime (string (@Date) , 3081, 'M yyyy'),1,2))+11),' ',
string(number(substring(ddwrt:FormatDateTime (string (@Date) , 3081, 'MM yyyy'),4))-1))=string(ddwrt:FormatDateTime (string ($date) , 3081, 'M yyyy'))
and number(substring(ddwrt:FormatDateTime(string(@Date), 3081, 'dd'),1,2)) <$startDay)])"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="count(/dsQueryResponse/Rows[1]/Row[(
(ddwrt:FormatDateTime (string (@Date) , 3081, 'M yyyy'))=(ddwrt:FormatDateTime (string ($date) , 3081, 'M yyyy'))
and number(substring(ddwrt:FormatDateTime(string(@Date), 3081, 'dd'),1,2)) >=$startDay)])+
count(/dsQueryResponse/Rows[1]/Row[(
concat(string(number(substring(ddwrt:FormatDateTime (string (@Date) , 3081, 'MM yyyy'),1,2))-1),
substring(ddwrt:FormatDateTime (string (@Date) , 3081, 'MM yyyy'),3,6))=(ddwrt:FormatDateTime (string ($date) , 3081, 'M yyyy'))
and number(substring(ddwrt:FormatDateTime(string(@Date), 3081, 'dd'),1,2)) <$startDay)])"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
<xsl:if test="msxsl:node-set($numMonths) > 0">
<xsl:call-template name="generateTable">
<xsl:with-param name="numMonths" select="msxsl:node-set($numMonths)-1" />
<xsl:with-param name="dvt_Rows"/>
<xsl:with-param name="Rows"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
在代码中,tday,tmonth和tyear是在d /月/今天的日期,NUMMONTHS是一个变量来保存在表中所要求的月数,并朝九特派为15
据我所知,向日期字段添加11个月的工作,但提取年份,将其更改为一个数字并减去1,就是问题出现的地方。但我无法实现它,所以我完全用完了简单的想法。
XML文档是Sharepoint列表,我不知道如何将其作为纯XML共享。我对XML的唯一参考是/ dsQueryResponse/Rows [1]/Row,它选择Sharepoint列表中的行,并使用Date字段(@Date)执行过滤器。这有帮助吗?
我使用的是Sharepoint 2007,我通过使用Sharepoint Designer通过插入dataFormWebPart来获取Sharepoint列表来开始。然后可以使用引用列表中所有行的xpath,/ dsQueryResponse/Rows/Row来访问XSLT中的Sharepoint列表。 (我在我的代码中添加了[1]来引用特定的列表,因为我有两个列表数据源)。
我宁愿首先在Sharepoint中过滤列表,并认为首先,但也许我做错了什么,因为我无法得到正是我想要的东西 - 其中包括零时没有条目对于特定的月份,以及月份过滤器的> = 15。我的方法几乎可行,这就是为什么它是如此令人沮丧,但我会欢迎任何替代品,尤其是如果它们更简单和/或更快。 感谢
您能不能请我们提供XML文档(尽可能最小化,以便说明问题)?我怀疑可能有更简单的解决方案,但需要使用XML文档。 – 2010-08-24 03:37:10
几个问题..什么版本的SharePoint?你如何从SharePoint列表中获取数据?另外,为什么使用XSLT过滤SharePoint列表?您不想查询列表(以过滤行),然后使用XSLT转换结果吗? – 2010-08-24 14:03:27