2012-10-26 68 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类似的变化。

相关问题