简体   繁体   English

如何显示“新的”子页面数Umbraco XSLT

[英]How to display “number of new” child pages Umbraco XSLT

I have two separate pieces of code I'm trying to combine. 我要尝试合并两个单独的代码段。

The first counts the number of child pages and displays a number: 第一个计算子页面的数量并显示一个数字:

eg 8 child pages (or child page, if only 1 page) 例如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>

The code detects if the page was created within the last 30 days: 该代码检测页面是否在最近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>

I want to combine them so I can get a count of child pages and a count of the "new" pages. 我想将它们结合起来,这样我就可以得到一个子页面数和一个“新”页面数。

eg 8 child pages - 2 new pages 例如8个子页面-2个新页面

I've tried the following but it doesn't return the correct values: 我尝试了以下操作,但未返回正确的值:

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

It returns: "true new pages" I don't know how to get it to display the number (2 new pages). 它返回:“真实的新页面”我不知道如何显示该数字(2个新页面)。

Can anyone help? 有人可以帮忙吗? Cheers, JV 欢呼声,合资企业

Look carefully at the contents you are specifying for the paragraph: 仔细查看您为该段指定的内容:

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

You have an and with a Boolean as the left argument and an integer as the right argument. 您有一个and ,布尔值为左参数,整数为右参数。 Put yourself in the processor's shoes: doesn't it look a lot as if you were asking it to calculate a Boolean value? 投入处理器的步伐:看起来不像您在要求它计算布尔值吗?

Since this expression is enclosed in a when element that already tests for the date difference, you (almost certainly) don't need to repeat the comparison of $datediff to 43200. (I say "almost certainly" because I don't think I understand the logic of your application in detail, so I could be wrong.) I suspect what you want to be saying is: 由于此表达式包含在已经测试过日期差的when元素中,因此您(几乎可以肯定)不需要重复$ datediff与43200的比较。(我说“几乎可以肯定”,因为我认为我不会详细了解您的应用程序的逻辑,所以我可能是错的。)我怀疑您想说的是:

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

You'll need an analogous change in the otherwise . 你需要在类似的变化otherwise

With many thanks to Chriztian Steinmeier: 非常感谢Chriztian Steinmeier:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM