Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XSLT 1.0 -- grouping items from a list of items of variable length >Thread Next - Re: XSLT 1.0 -- grouping items from a list of items of variable le Re: XSLT 1.0 -- grouping items from a list of items of variable lengthTo: NULL Date: 12/1/2006 8:24:00 PM "J Hendrich" <jhendrich@n...> wrote in message news:16B641CA-3BD7-4287-B743-55081A2376E8@m...... > Hi, > > I want to transform a list of items that can be of variable length into > groups of 6 items each, with the last group possibly having less than 6. > > For example, the source list might have 40 items. I therefore would want to > achieve 6 groups of 6 items plus a 7th group of 4 items. > > Specifically, given a list of images, I want to create n pages with 6 images > each. > > Question: Is there a way to do this, or is this a limitation of XSLT? > > For reference, you can see how I had originally intended to do this...except > that it doesn't work due to needing to mismatch start and end tags. > > Example source xml: > > <Images> > <Image>23.01.20 hrs __[0000033].bmp</Image> > <Image>23.01.16 hrs __[0000034].bmp</Image> > <Image>01.45.16 hrs __[0000035].bmp</Image> > <Image>01.45.20 hrs __[0000039].bmp</Image> > <Image>01.45.20 hrs __[0000043].bmp</Image> > <Image>01.45.16 hrs __[0000044].bmp</Image> > <Image>02.45.16 hrs __[0000053].bmp</Image> > <Image>02.45.20 hrs __[0000063].bmp</Image> > <Image>03.45.20 hrs __[0000072].bmp</Image> > <Image>03.45.16 hrs __[0000077].bmp</Image> > <Image>04.45.20 hrs __[0000044].bmp</Image> > <Image>04.45.16 hrs __[0000045].bmp</Image> > <Image>23.57.21 hrs __[0000005].jpeg</Image> > <Image>18.34.27 hrs __[0000006].jpeg</Image> > <Image>21.59.27 hrs __[0000006].jpeg</Image> > <Image>22.57.21 hrs __[0000105].jpeg</Image> > </Images> > > XSLT: > > <xsl:template match="Images"> > > <!-- insert a page break --> > <p style="page-break-before: always;"> > > <!-- display is 6-up per page --> > <table class="n6up"> > <xsl:for-each select="Image"> > <xsl:if test="position() mod 6 = 0"> > </table> > </p> > <p style="page-break-before: always;"> > <table class="n6up"> > </xsl:if> > <xsl:if test="position() mod 2 = 1"> > <tr> > <td class="n6up"> > <xsl:element name="img"> > <xsl:attribute name="class"><xsl:value-of > select="'nUpImage'"/></xsl:attribute> > <xsl:attribute name="src"><xsl:value-of > select="string(.)"/></xsl:attribute> > <xsl:attribute name="alt"><xsl:value-of > select="string(.)"/></xsl:attribute> > </xsl:element> > </td> > </xsl:if> > <xsl:if test="position() mod 2 = 0"> > <td class="n6up"> > <xsl:element name="img"> > <xsl:attribute name="class"><xsl:value-of > select="'nUpImage'"/></xsl:attribute> > <xsl:attribute name="src"><xsl:value-of > select="string(.)"/></xsl:attribute> > <xsl:attribute name="alt"><xsl:value-of > select="string(.)"/></xsl:attribute> > </xsl:element> > </td> > </tr> > </xsl:if> > </xsl:for-each> > </table> > </p> > </xsl:template> > Fundementally you need two loops. an outer loop to select the first image and every sixth image after that. And an inner loop to select that image and the 5 following sibilings. Hence:- <xsl:for-each select="item[position() mod 6 = 1]"> <xsl:for-each select=". | following-sibling::item[position() < 6]"> <img ...whatever /> </xsl:for-each> <p ...throw page.. /> </xsl:for-each> > > Thanks. > Jon > -- > "When in the company of others, I shall always consider myself the lowest of > all" | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
