2013-05-29 23 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>定義函數的返回類型。