Search

Hi Ninjas,

I'm trying to count a number of sub section image and video entries so that I can display a count under each item.. i.e 1/8,2/8,3/8 etc..

The images and video entries are subsections of the main section so I can't use position() as it will reset when it gets to the videos right?

What would be the best way to approach this in terms of xslt?

How does you XML look like and what is your desired output exactly?

Xpathr here: XML data structure

This line in the XSL template is what I've currently got but it obviously is just counting the iteration of images: <p><xsl:value-of select="position()/."/>/<xsl:value-of select="count(../item)"/><xsl:if test="position() = '1'"> / <xsl:value-of select="../../title"/></xsl:if></p>

What should it count else?
That line is only present in the templates that's matched on the images.

Yes I know. What I'm attempting to do is have it tally the total of images and videos in an entry. Then render the position of the images and videos in the output numerically. If you look at the result of the xpathr it works with the images right now but not the videos because I can't think of a way to link the 2 nodes together to create a total count.

I'm a bit lost. Could you please post what the markup should look like in the end?

Ok I've got this far now: <xsl:for-each select="descendant::item"> <xsl:value-of select="position()"/>/<xsl:value-of select="count(//item)"/> </xsl:for-each>

But the item count shows 1. What would be the reverse of descendant?

Something like this:

<img src="" />
<p>1/4</p>
<img src="" />
<p>2/4</p>
<img src="" />
<p>3/4</p>
<video src=""/>
<p>4/4</p>

It does indeed. Much appreciated Nils. Case closed.

Hi Nils, thanks for your help on this, I think this may be a priority issue on the template but when I add my matched templates for manipulating the images and video markup.. the count match on item do not appear anymore. Would you happen to know why this may be? Xpathr latest with my matched templtaes.

Yes, the templates matching videos/item and images/item are more specific and thus fire instead of the more general template matching item only. Using modes should help: http://xpathr.com/view/3750561/654e9c5582e283d46e706174ed448310ee9539bb/.

Ok, I think I've nailed it: xpathr latest. May not be the most elegant but it seems to work for me.

Checkout the modes version above that will remove the conditionals and make things a bit smarter.

Ah thanks Nils. This is really really helpful stuff.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details