0

I have some code that looks like this:

<xsl:for-each select="($home/item[@key='issues']/item[@key='cwa']/item[@key='archives']/item[@key='2012']/*/*)">
    <xsl:if test="(position() &lt; 15) and (position() &gt; 1)">
    ...

It works fine, except there are hundreds of items in the result set, and I only want to show 20. The structure beneath 2012 looks something like this

2012
  01
  02
  03

So in theory I only need the current month and last month. Is there a way to limit that in the for-each statement itself?

This is in the Sitecore CMS, so unfortunately I don't have easy access to the raw XML.

Jon
  • 846
  • 1
  • 8
  • 25

2 Answers2

0

I have made the experience that a "template - apply-templates" construct is better performance wise. I also had a XML with hundreds of items. In the particular case I had to rename elements and the performace gain was almost 30 seconds.

Also for other reasons I would recommend to use the "template - apply-templates" construct: For loops vs. apply-templates

I am sure you can also adapt the code in your example.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
Peter
  • 1,786
  • 4
  • 21
  • 40
0

You could also create an XSL extension to populate the foreach. In the XSL extension you could use Linq to select only the items that you really need.

Another drawback of having hundreds of items as a child items is that the content editor could become very slow when you try to open the parent item. Dividing the child items automatically into folders per month for example, could resolve this (or try the ItemBuckets package of Tim Ward for another approach with using Lucene Search index)

Edit: just comes to mind that defining the select in the for-loop before doing the actual loop could also gain some performance improvement, like this. (not exactly sure if this is true, by the way ;) )

<xsl:variable name="list" select="($home/item[]..... etc.)" />
<xsl:for-each select="$list>
 ....
Martijn van der Put
  • 4,062
  • 1
  • 18
  • 26