0
votes

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

2
Your qustion and provided stuffs are not clear. Please put some more stuffs to understand clearly.Navin Rawat
Thank you Navin for your answer I've edited and add a new post...Benjamin
Hi @NavinRawat did you see the new comments and answers??Benjamin

2 Answers

0
votes

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: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>
0
votes

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. Only when my page as at least 1 child publish it shows me the page. Here is my xslt code

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

Thanks for your help. Benjamin