Are you trying to create rows or columns? Either way, I would create an <ul> with a maximum of three <li> as long as there are nodes to process.
The operator you're probably searching for is "mod" (often the % operator in other languages). It's the modulus, e.g. "4 mod 3" equals 1, "5 mod 3" equals 2, "6 mod 3" equals 0. So, every number divided by 3, for which the remainder is 0 ==> is a multiple of 3.
Using the position() in XSLT, you can find out "where you are" in the nodeset (e.g. in the for-each loop) and insert an <ul> or <li> accordingly.
<ul>
<xsl:for-each select="$currentPage/node">
<!-- position() starts at 1, not 0 like a 'normal' index -->
<xsl:if test="((position() - 1) mod 3) = 0">
<!-- It's the 1st, 4th, 7th in the set-->
<li>
</xsl:if>
<!-- Do your thing with the current node here -->
<xsl:if test="(position() mod 3) = 0">
<!-- It's the 3rd, 6th, 9th node in the set -->
</li>
</xsl:if>
</xsl:for-each>
</ul>
Might give you errors on saving because it finds unclosed pairs of tags (the <li></li> pair that is). You could wrap them in CDATA sections to prevent those errors.
Count childs in <li> and make <li> if more than three
Hi
I'm trying to this:
How do I do this in XSLT?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets umbraco.contour PS.XSLTsearch ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:variable name="documentTypeAlias" select="string('Customer')"/>
<xsl:template match="/">
<div id="kundeliste"> <a class="buttons prev" href="#empty-anchor">left</a>
<div class="viewport">
<ul class="overview">
<xsl:for-each select="$currentPage/* [name() = $documentTypeAlias and string(umbracoNaviHide) != '0']">
<li>
<span><span><img src="/imgs/kundelistePhone.png" width="58" height="84" /></span><strong><xsl:value-of select="customerHeadline"/></strong><xsl:value-of select="customerText"/></span>
</li>
</xsl:for-each>
</ul></div>
<a class="buttons next" href="#empty-anchor"><span class="btn">right</span></a></div>
</xsl:template>
</xsl:stylesheet>
This is my code untill now :) - now i just need some kind of logic counting childs and creating a new <li></li> with childs in when there is 3 childs.
- Help :-)
Shoot! I misread the whole thing, so I've removed the code I posted :-)
Now I can see you're basically creating a 3-column table - take a look at my answer here:
http://our.umbraco.org/forum/developers/xslt/11527-Problem-with-listing-HTLM-strcuture-with-XSLT
/Chriztian
Are you trying to create rows or columns? Either way, I would create an <ul> with a maximum of three <li> as long as there are nodes to process.
The operator you're probably searching for is "mod" (often the % operator in other languages). It's the modulus, e.g. "4 mod 3" equals 1, "5 mod 3" equals 2, "6 mod 3" equals 0. So, every number divided by 3, for which the remainder is 0 ==> is a multiple of 3.
Using the position() in XSLT, you can find out "where you are" in the nodeset (e.g. in the for-each loop) and insert an <ul> or <li> accordingly.
I just want a list of products with 4 nodes in each <li>.
Chriztian: will check it out
Thijs: I understand what you are saying, but i just can't figure out how to do it.. Will work on it :)
The ugly way:
Might give you errors on saving because it finds unclosed pairs of tags (the <li></li> pair that is). You could wrap them in CDATA sections to prevent those errors.
is working on a reply...