调用过滤功能

时间:2013-05-29 09:19:03

标签: xslt xslt-2.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>

1 个答案:

答案 0 :(得分: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>定义函数的返回类型,则可以获得更好的错误诊断。