Xslt 用于过滤的调用函数
此函数“karusell:isCurrentDateTimeBetweenDates”从未被调用。为什么我不能使用它进行过滤?如果我单独调用一个函数并将其存储在一个变量中,它就会工作。变量的值为falseXslt 用于过滤的调用函数,xslt,xslt-2.0,Xslt,Xslt 2.0,此函数“karusell:isCurrentDateTimeBetweenDates”从未被调用。为什么我不能使用它进行过滤?如果我单独调用一个函数并将其存储在一个变量中,它就会工作。变量的值为false <xsl:variable name="bannerList" select="verticaldata/contents/content[ karusell:isCurrentDateTimeBetweenDates( 'Thursday', '01' , 'Friday', '0
<xsl:variable name="bannerList" select="verticaldata/contents/content[ karusell:isCurrentDateTimeBetweenDates( 'Thursday', '01' , 'Friday', '03') ][position() <= 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 >= $startDateTime and $currentDateTime < $endDateTime" />
</xsl:function>
使用
xsl:sequence
,而不是xsl:value of
返回表达式的数据类型值。因此,替换
<xsl:value-of select="$currentDateTime >= $startDateTime and $currentDateTime < $endDateTime" />
与
此外,如果您使用
定义函数的返回类型,您可以获得更好的错误诊断。
请考虑向我们显示最小但完整的示例,以便我们重现问题。恐怕仅仅凭这一段就很难帮助你了?那么函数代码看起来如何?您如何注意到函数没有被调用?哪个变量的值为false?bannerList
变量应该是一系列content
元素,而不是true或false。谢谢。我的问题是,我的函数返回字符串'false'而不是布尔值。
<xsl:sequence select="$currentDateTime >= $startDateTime and $currentDateTime < $endDateTime" />