0

这个函数“karusell:isCurrentDateTimeBetweenDates”永远不会被调用。为什么我不能用它来过滤?如果单独调用 i 并将其存储在变量中,它将起作用。变量的值为假。

 <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>
4

1 回答 1

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>

于 2013-05-29T10:10:06.647 回答