Thanks Chriztian - your solution looks great ... although I'm not sure the code is displaying correctly? E.g. is "-templates" meant to be "xsl:apply-templates"?
Also, would it be easy to alter it to work for 3 nodes at a time?
- and here's an Umbraco-adapted version of that Gist:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:umb="urn:umbraco.library"
exclude-result-prefixes="umb"
>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:param name="currentPage" />
<!-- Select the nodes to output here -->
<xsl:variable name="nodes" select="$currentPage/*[@isDoc]" />
<xsl:variable name="groupSize" select="3" />
<xsl:template match="/">
<!-- Apply the "group" mode template to the first element of every group -->
<xsl:apply-templates select="$nodes[(position() mod $groupSize) = 1]" mode="group" />
</xsl:template>
<!-- Template for 1st item in every group -->
<xsl:template match="*" mode="group">
<ul>
<!-- Apply the "item" mode template to all elements in the group -->
<xsl:apply-templates select=". | following-sibling::*[@isDoc][position() < $groupSize]" mode="item" />
</ul>
</xsl:template>
<!-- Template for every item -->
<xsl:template match="*" mode="item">
<li>
<xsl:value-of select="." />
</li>
</xsl:template>
</xsl:stylesheet>
If this doesn't display right in your browser we need to ping the Umbraco team about it...
Output nodes in blocks of LI's
I have a set of nodes and I need to output them in blocks of 3 wrapped in UL tags.
E.g.
UL
LI
Node details 1
/LI
(3 of the above)
/UL
UL
LI
Node Details 4
(3 of the above)
?LI
/UL
and so on
I am not sure how to conditionally output the UL and /UL tags without causing errors!?
Umm, I found this "solution" but it just seems wrong!!?
Hi Gordon,
Though it "works" - it *is* wrong yes :-)
Check my answer here for a better way to do this:
/Chriztian
Thanks Chriztian - your solution looks great ... although I'm not sure the code is displaying correctly? E.g. is "-templates" meant to be "xsl:apply-templates"?
Also, would it be easy to alter it to work for 3 nodes at a time?
Hi Gordon,
Sounds odd??? Displays fine here - may be a browser issue then.
I created a more generic example here: https://gist.github.com/1293712
/Chriztian
- and here's an Umbraco-adapted version of that Gist:
If this doesn't display right in your browser we need to ping the Umbraco team about it...
/Chriztian
Thanks Chriztian - that is / you are awesome!!! :-) Works a treat!
is working on a reply...