2012-10-26 32 views
0

我有兩個單獨的代碼片段,我試圖結合。如何顯示「新數量」的子頁面Umbraco XSLT

第一計數子頁面的數量,並顯示一個數字:

例如8子頁面(或子頁面,如果只有1頁)

<xsl:choose> 
<xsl:when test="count(child::DocTypeAlias) &gt; 1"> 
    <p><xsl:value-of select="count(child::DocTypeAlias)"/> child pages</p> 
</xsl:when> 
<xsl:otherwise> 
    <p><xsl:value-of select="count(child::DocTypeAlias)"/> child page</p> 
</xsl:otherwise> 

如果頁面是在過去30天內創建的代碼檢測:

<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" /> 
    <xsl:if test="$datediff &lt; (1440 * 30)"> 
     <p>New</p> 
    </xsl:if> 

我希望將它們組合所以我可以得到一些子頁面和一些「新」頁面。

例如8個頁面 - 2個新頁面

我試過以下,但它不返回正確的值:

<xsl:variable name="datediff" select="umbraco.library:DateDiff(umbraco.library:ShortDate(umbraco.library:CurrentDate()), umbraco.library:ShortDate(@createDate), 'm')" /> 
    <xsl:choose> 
     <xsl:when test="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias) &gt; 1"> 
      <p><xsl:value-of select="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias)"/> new pages</p> 
     </xsl:when> 
     <xsl:otherwise> 
      <p><xsl:value-of select="$datediff &lt; (1440 * 30) and count(child::DocTypeAlias)"/> new page</p> 
     </xsl:otherwise> 
    </xsl:choose> 

它返回:「真正的新頁面」我不知道怎麼弄它顯示數字(2個新頁面)。

任何人都可以幫忙嗎?歡呼聲中,JV

回答

0

隨着許多感謝Chriztian施泰因邁爾:

<!-- The date calculation stuff --> 
<xsl:variable name="today" select="umb:CurrentDate()" /> 
<xsl:variable name="oneMonthAgo" select="umb:DateAdd($today, 'm', -1)" /> 

<!-- Grab the nodes to look at --> 
<xsl:variable name="nodes" select="$currentPage/DocTypeAlias" /> 

<!-- Pages created within the last 30 days --> 
<xsl:variable name="newPages" select="$nodes[umb:DateGreaterThanOrEqual(@createDate, $oneMonthAgo)]" /> 
<xsl:template match="/"> 
    <xsl:choose> 
    <xsl:when test="count($newPages)"> 
     <p> <xsl:value-of select="count($newPages)" /> <xsl:text> New Page</xsl:text> 
     <xsl:if test="count($newPages) &gt; 1">s</xsl:if> 
     </p> 
    </xsl:when> 
    <xsl:otherwise> 
    </xsl:otherwise> 
    </xsl:choose> 
</xsl:template> 
1

仔細看一下您指定段落的內容:

<p> 
    <xsl:value-of select=" 
    $datediff &lt; (1440 * 30) 
    and 
    count(child::DocTypeAlias)"/> 
    new pages 
</p> 

你有一個and與布爾作爲左邊參數和整數右邊的參數。把自己放在處理器的鞋子裏:它看起來不像你要求它計算一個布爾值嗎?

由於此表達式包含在已經測試日期差異的when元素中,因此您(幾乎可以肯定)不需要重複$ datediff與43200的比較(我幾乎可以肯定地說「因爲我不會。「T想我詳細瞭解應用程序的邏輯,所以我可能是錯的),我懷疑你想被說的話是:

<p> 
    <xsl:value-of select="count(child::DocTypeAlias)"/> 
    new pages 
</p> 

你需要在otherwise類似的變化。

相關問題