2013-05-29 26 views
0

这个函数“karusell:isCurrentDateTimeBetweenDates”永远不会被调用。为什么不能使用它进行过滤?如果单独打一个电话并将其存储在一个变量中,它就可以工作。该变量的值为false。调用函数进行过滤

<xsl:variable name="bannerList" select="verticaldata/contents/content[ karusell:isCurrentDateTimeBetweenDates('Thursday', '01' , 'Friday', '03') ][position() &lt;= 5]" /> 

编辑: 如何返回字符串?

过滤

功能

<xsl:function name="karusell:isCurrentDateTimeBetweenDates">  
    <xsl:param name="startDay"/> 
    <xsl:param name="startHour" /> 
    <xsl:param name="endDay"/> 
    <xsl:param name="endHour" /> 
    <xsl:variable name="currentDateTime" select="current-dateTime() " /> 


    <xsl:variable name="todayIndex" select="karusell:getDayIndex(format-dateTime($currentDateTime , '[F]'))" /> 
    <xsl:variable name="startDayIndex" select="karusell:getDayIndex($startDay)" /> 
    <xsl:variable name="endDayIndex" select="karusell:getDayIndex($endDay)" /> 

    <xsl:variable name="startDate" select= "$currentDateTime - ($todayIndex - $startDayIndex)*xs:dayTimeDuration('P1D')"/> 
    <xsl:variable name="endDate" select= "$currentDateTime + ($endDayIndex - $todayIndex)*xs:dayTimeDuration('P1D')"/> 


    <xsl:variable name="startDateTime" select="format-dateTime($startDate, concat('[Y0001]-[M01]-[D01]T', $startHour ,':00:00')) cast as xs:dateTime"/> 
    <xsl:variable name="endDateTime" select="format-dateTime($endDate, concat('[Y0001]-[M01]-[D01]T', $endHour ,':00:00')) cast as xs:dateTime"/> 

    <xsl:value-of select="$currentDateTime &gt;= $startDateTime and $currentDateTime &lt; $endDateTime" /> 
</xsl:function> 
+0

考虑向我们展示最小但完整的样本,使我们能够重现问题。我很害怕这个片段很难提供帮助吗?那么功能代码看起来如何?你怎么注意到函数没有被调用?哪个变量的值是错误的? 'bannerList'变量应该是一系列'content'元素,不是真或假。 –

+0

谢谢。我的问题是,我的函数返回字符串'假'不是布尔值。 – pethel

回答

1

使用xsl:sequence,不xsl:value-of返回数据的值键入表达式。所以更换

<xsl:value-of select="$currentDateTime &gt;= $startDateTime and $currentDateTime &lt; $endDateTime" /> 

<xsl:sequence select="$currentDateTime &gt;= $startDateTime and $currentDateTime &lt; $endDateTime" /> 

此外,您可以得到更好的诊断错误,如果你有<xsl:function name="pf:foo" as="xs:boolean">..</xsl:function>定义函数的返回类型。