XSLT split result in groups of 3

vchesh

New Member
An web-application is providing me an XML-feed, which I can't change. What I want to do is split this XML-feed into several unordered lists. I'm trying to do this with the XSLT below.\[code\]<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:eek:utput method="xml" omit-xml-declaration="yes" indent="yes" encoding="utf-8" /> <xsl:param name="html-content-type" /> <xsl:template match="/NavigationTree"> <xsl:if test="count(//Page) > 0"> <ul> <xsl:apply-templates select="Page"> </xsl:apply-templates> </ul> </xsl:if> </xsl:template> <xsl:template match="//Page"> <li class="{position() mod 3}"> <xsl:text disable-output-escaping="yes"><![CDATA[?&nbsp;]]></xsl:text> <a> <xsl:attribute name="href"> <xsl:value-of select="@FriendlyHref" disable-output-escaping="yes"/> </xsl:attribute> <xsl:value-of select="@MenuText" disable-output-escaping="no"/> </a> </li> <xsl:if test="position() mod 3 = 0"> <xsl:if test="position() < count(//Page)"> <!--Don't know if this is the correct approach, but when the position is 3 and there are more items following I want to create an new unordered list--> </xsl:if> </xsl:if> </xsl:template></xsl:stylesheet>\[/code\]Using the XSLT above i'm able to turn the XML into an unordered list with 6 items in it (let's assume there always are 6 items). Similar to the example below;\[code\]<ul> <li>Item1</li> <li>Item2</li> <li>Item3</li> <li>Item4</li> <li>Item5</li> <li>Item6</li></ul>\[/code\]The example above is the result i'm getting at the moment. But the desired result is something like this;\[code\]<ul> <li>Item1</li> <li>Item2</li> <li>Item3</li></ul><ul> <li>Item4</li> <li>Item5</li> <li>Item6</li></ul>\[/code\]EDIT - Sample XML input\[code\]<NavigationTree> <Settings> <!--Snipped data--> </Settings> <Page ID="5" AreaID="1" MenuText="Bestellen" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=5" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/bestellen.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="1" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/> <Page ID="6" AreaID="1" MenuText="Betalen" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=6" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/betalen.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="2" LastInLevel="False" InPath="True" ChildCount="0" class="L2_Active" Active="True" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/> <Page ID="7" AreaID="1" MenuText="Retourneren" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=7" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/retourneren.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="3" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/> <Page ID="8" AreaID="1" MenuText="Garantie" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=8" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/garantie.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="4" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/> <Page ID="9" AreaID="1" MenuText="Faq" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=9" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/veel-gestelde-vragen.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="5" LastInLevel="False" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/> <Page ID="10" AreaID="1" MenuText="Contact" MouseOver="" Href="http://stackoverflow.com/questions/7316260/Default.aspx?ID=10" FriendlyHref="http://stackoverflow.com/nl-nl/klantenservice/contact.aspx" Image="" ImageActive="" ImageMouseOver="" Title="" Allowclick="True" ShowInSitemap="True" ShowInLegend="True" AbsoluteLevel="2" RelativeLevel="2" Sort="6" LastInLevel="True" InPath="False" ChildCount="0" class="L2" Active="False" IsPagePasswordProtected="False" IsPageUserProtected="False" CanAccessPasswordProtectedPage="False" CanAccessUserProtectedPage="True"/></NavigationTree>\[/code\]As you can see I always want output in groups of 3 items. Is this kind of html output possible using XSLT? If yes, how can I do this? Any help is welcome!
 
Top