[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Trouble creating tables while looping through ele
Wrong approach: XSLT stylesheets produce a tree as the output, not lexical XML; XSLT instructions create nodes on the tree, not tags in the serialized XML. So you can't write end tags and start tags as separate operations. This is a grouping problem and in XSLT 2.0 you can write <xsl:for-each-group select="node" group-by="subnode"> <xsl:sort select="current-grouping-key()"/> <table> <xsl:for-each-select="current-group()"> .... </ </ </ It's more tricky to achieve if you're stuck with XSLT 1.0: search for "Muenchian Grouping". The code is rather confusing, but not difficult once you understand it. Regards, Michael Kay http://www.saxonica.com/ http://twitter.com/michaelhkay > -----Original Message----- > From: Charles-Louis De Maere > [mailto:charles-louis.demaere@xxxxxxxxxxxxxxx] > Sent: 10 May 2010 09:14 > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Trouble creating tables while looping through elements > > Dear all, > > I'm looping through a (sorted) list of nodes, and would like > to put them in different tables based on a certain condition > using xslt. > > At the moment, I'm doing the following : > > <table> > <xsl:for-each select="node"> > <tbody> > ... some formatting ... > </tbody> > <xsl:if test="not(subnode = following-sibling::node/subnode)"> > </table> > <h2>Some Title</h2> > <table> > </xsl-if> > </xsl:for-each> > </table> > > However, this XSLT file is invalid (XMLSpy indicates a > warning when I save it, because of the closing <table> tag > underneath the if-test), and Firefox refuses to display it > for the same reason. > > Is there any easy way to have some kind of separation within > the for-each loop, or should I take this formatting out of the loop ? > > > Thanks in advance, > > Charles-Louis de Maere
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|