0

Needs some help. In umbraco I have my tree like this

-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? (in this example 3) Here's my 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

first link

second link

4

2 回答 2

0

您可以像这样计算您浏览的页面总数:

count($articles/* [@isDoc and string(umbracoNaviHide)!='1' and local-name(current())='myfilteredpage'])

如果您想在循环中包含当前的“计数”,您应该像这样更改您的 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>
于 2013-05-29T08:07:16.843 回答
0

我试过你给的计数器......当需要显示 2 时,计数器显示 0。我发现我的 xsl 的另一种行为尚不清楚。只有当我的页面作为至少 1 个孩子发布时,它才会向我显示该页面。这是我的 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>

试着解释一下。这是我的示例树

-first page
  -page
  -article1 (published)
    -article2 (unpublished)
    -article3 (unpublished)
  -page
  -page
  -page
  -article4 (published)
  -page
  -article5 (published)
    -article6 (published)
    -article7 (unpublished)
  -page...

实际上我的代码只会创建 article5 (子项 (article6,7) 创建是在 xslt 评论中)但是正如你所看到的 article1 和 article4 没有被创建......我不明白为什么......

谢谢你的帮助。本杰明

于 2013-05-29T09:30:52.520 回答