Using xsl:for-each to populate an XSL-FO table

stevestraughn

New Member
I need to populate a table using XSL-FO with a dynamic number of rows, from an XML document.What I've been trying to do is something like this:\[code\]<xsl:template match="topLevel"> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master margin-right=".25in" margin-left=".25in" margin-top=".5in" margin-bottom=".5in" page-width="8.5in" page-height="11in" master-name="title"> <fo:region-body/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="title"> <fo:flow flow-name="xsl-region-body"> <fo:block>Title</fo:block> <xsl:apply-templates select="otherData"/> <xsl:apply-templates select="prts"/> </fo:flow> </fo:page-sequence> </fo:root></xsl:template><xsl:template match="prts"> <fo:block> <fo:table> <fo:table-column/> <fo:table-column/> <fo:table-column/> <fo:table-body> <xsl:for-each select="foo"> <fo:table-row> <fo:table-cell> <fo:block>something</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>something</fo:block> </fo:table-cell> <fo:table-cell> <fo:block>something</fo:block> </fo:table-cell> </fo:table-row> </xsl:for-each> </fo:table-body> </fo:table> </fo:block></xsl:template>\[/code\]The XML is structured like this:\[code\]<topLevel> <otherData> ... </otherData> <prts> <foo> ... </foo> <foo> ... </foo> </prts></topLevel>\[/code\]When I do this though, I get the error:\[quote\] ""fo:table-body" is missing child elements. Required content model: marker* (table-row+|table-cell+)"\[/quote\]I've seen this syntax and structure used in tons of examples, but for some reason I get this error every time. I've also tried moving the xsl:for-each around (e.g. putting it outside the fo:table-body, but no matter where I move it to, I end up getting the same error, only for whatever element is directly outside the xsl:for-each instead of always for the fo:table-body element.So how do I use xsl:for-each to build this table?
 
Back
Top