[英]Umbraco xslt count filtered pages
Needs some help. 需要一些帮助。 In umbraco I have my tree like this
在umbraco,我有这样的树
-First
- page 1
- page 2
- page 3
- page 4
- page 5
- page 6
- page 7
- page 8
- page 9
- page 10
- page 11
- page 12...
looping all the pages i filter them. 循环所有页面我过滤它们。 So I apply my xslt only to pages 4,7,10 position() will give me 4,7,10 How can I count the number of pages i walked through?
所以我只将xslt应用于第4,7,10页position()会给我4,7,10如何计算我浏览的页面数? (in this example 3) Here's my xslt:
(在此示例3中)这是我的xslt:
<xsl:param name="currentPage"/>
<xsl:variable name="root" select="$currentPage/ancestor-or-self::* [@isDoc][last()]"/>
<xsl:variable name="articles" select="$root/descendant-or-self::* [@isDoc][@level=2]"/>
<xsl:template match="/">
<xsl:for-each select="$articles">
<xsl:if test="./* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='myfilteredpage']">
...some html construction...
</xsl:if>
</xsl:for-each>
</xsl:template>
Thank you for your help. 谢谢您的帮助。 Benjamin
本杰明
PS: found those link that helped me to build the pagination but my counter isn't resolved PS:找到那些有助于我建立分页的链接,但我的柜台无法解决
you can count the total number of pages you walk through like this: 您可以像这样计算遍历的页面总数:
count($articles/* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='myfilteredpage'])
If you would like to have current 'count' inside your loop, you should change your xsl like this: 如果您希望循环中具有当前的“计数”,则应按以下方式更改xsl:
<xsl:param name="currentPage"/>
<xsl:variable name="root" select="$currentPage/ancestor-or-self::* [@isDoc][last()]"/>
<xsl:variable name="articles" select="$root/descendant-or-self::* [@isDoc][@level=2]"/>
<xsl:template match="/">
<xsl:variable name="articlesToLoop" select="$articles//* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='myfilteredpage']" />
<xsl:for-each select="$articlesToLoop">
Current count: <xsl:value-of select="position()" />
- <xsl:value-of select="@nodeName" />
</xsl:for-each>
</xsl:template>
I've tried the counter you give... The counter show 0 when it needs to show 2. I've found another behaviour of my xsl that is not clear. 我尝试了您提供的计数器...当计数器需要显示2时,计数器显示0。我发现xsl的另一种行为不清楚。 Only when my page as at least 1 child publish it shows me the page.
只有当我的页面(至少有1个孩子)发布时,它才会显示该页面。 Here is my xslt code
这是我的xslt代码
<xsl:param name="currentPage"/>
<xsl:variable name="root" select="$currentPage/ancestor-or-self::* [@isDoc][last()]"/>
<xsl:variable name="articles" select="$root/descendant::* [@isDoc][@level=2]"/>
<xsl:variable name="NumberOfCharactersToShow" select="number(400)"/>
<xsl:template match="/">
<!-- start writing XSLT -->
<xsl:variable name="counter" select="count($articles//* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='Article'])" />
<xsl:value-of select="$counter" />
<xsl:for-each select="$articles">
<xsl:variable name="article" select="* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='Article']" />
<xsl:if test="$article">
<xsl:call-template name="article" />
<!--<xsl:for-each select="current()/descendant::* [@isDoc]">
<xsl:call-template name="article" />
</xsl:for-each>-->
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template name="article">
<xsl:variable name="text" select="umbraco.library:StripHtml(umbraco.library:TruncateString(bodyText,$NumberOfCharactersToShow,'...'))"/>
<!--article-->
<div class="article border border-radius border-shadow">
<div class="atitle">
<p><xsl:value-of select="title" /></p>
</div>
<div class="atext">
<p><xsl:value-of select="$text" /></p>
</div>
</div>
</xsl:template>
Try to explain. 尝试解释一下。 Here is my example tree
这是我的示例树
-first page
-page
-article1 (published)
-article2 (unpublished)
-article3 (unpublished)
-page
-page
-page
-article4 (published)
-page
-article5 (published)
-article6 (published)
-article7 (unpublished)
-page...
actually my code will create only article5 (the children (article6,7) creation is in xslt comments) But as you can see article1 and article4 are not created...I don't understand why... 实际上我的代码只会创建article5(子项(article6,7)的创建在xslt注释中),但是正如您所看到的,未创建article1和article4……我不明白为什么……
Thanks for your help. 谢谢你的帮助。 Benjamin
本杰明
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.