anmarie63 Posted December 10, 2009 Share Posted December 10, 2009 I am a beginner to XSL-FO, I am trying to produce a table(XSL) with alternating row colors. I've found several examples that use position/mod but I want to do this without linking to node positions in the XML document, if possible? Link to comment Share on other sites More sharing options...
Martin Honnen Posted December 10, 2009 Share Posted December 10, 2009 Well if you use the position() function then it is not necessarily linked to node positions, rather it is linked to the order you process items with in your stylesheet.I am not really sure what you want to achieve when you say you want "to produce a table with alternating row colors" ... "without linking to node positions". Are the rows in the table not filled with data from nodes in an XML input document? Link to comment Share on other sites More sharing options...
anmarie63 Posted December 11, 2009 Author Share Posted December 11, 2009 Well if you use the position() function then it is not necessarily linked to node positions, rather it is linked to the order you process items with in your stylesheet.I am not really sure what you want to achieve when you say you want "to produce a table with alternating row colors" ... "without linking to node positions". Are the rows in the table not filled with data from nodes in an XML input document?Here's the XSL for the table body and the XML. Rows 2(addRecord), 4(editRecord), 5(toggleRecord), and 7(updateEntry) are shaded. I want alternating row shading regardless of the node position in the XML document.<fo:table-body><xsl:variable name="varNormalBGColor">rgb(255,255,255)</xsl:variable><xsl:variable name="varAccentBGColor">rgb(230,230,230)</xsl:variable><xsl:for-each select="category/attribute"><xsl:if test="property='private methods'"><fo:table-row><xsl:attribute name="background-color"><xsl:choose><xsl:when test="(position() mod 2) = 0"><xsl:value-of select="$varNormalBGColor"/></xsl:when><xsl:otherwise><xsl:value-of select="$varAccentBGColor"/></xsl:otherwise></xsl:choose></xsl:attribute><fo:table-cell padding="5pt,10pt" border-style="solid" border-color="rgb(166,166,166)"><fo:block><fo:external-graphic src="C:\arrow.png" content-width="9pt" content-height="9pt"/></fo:block></fo:table-cell><fo:table-cell padding="5pt" border-style="solid" border-color="rgb(166,166,166)"><fo:block font-weight="bold"><xsl:value-of select="name"/></fo:block><fo:block font-weight="normal" font-family="tahoma"><xsl:value-of select="description"/></fo:block></fo:table-cell><fo:table-cell padding="1pt" border-style="solid" border-color="rgb(166,166,166)"><fo:block><xsl:value-of select="defined"/></fo:block></fo:table-cell></fo:table-row></xsl:if></xsl:for-each></fo:table-body> XML <category><attribute><name>numOfEntries</name><description>numOfEntries description</description><property>public</property><defined>smith3</defined></attribute><attribute><name>updateRecord()</name><description>updateRecord() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>addRecord()</name><description>addRecord() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>removeRecord()</name><description>removeRecord() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>id</name><description>id description</description><property>public</property><defined>smith</defined></attribute><attribute><name>className</name><description>className description</description><property>public</property><defined>smith2</defined></attribute><attribute><name>editRecord()</name><description>editRecord() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>class_buf</name><description>class_buf description</description><property>private</property><defined>smith6</defined></attribute><attribute><name>toggleRecord()</name><description>toggleRecord() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>valid()</name><description>valid() description</description><property>private methods</property><defined>smith1</defined></attribute><attribute><name>updateEntry()</name><description>updateEntry() description</description><property>private methods</property><defined>smith1</defined></attribute></category> Link to comment Share on other sites More sharing options...
Martin Honnen Posted December 11, 2009 Share Posted December 11, 2009 I think instead of xsl:for-each with a nested xsl:if you simply want <xsl:for-each select="category/attribute[property='private methods']"> and then remove the xsl:if but continue to use the position() function as you have. As I said, it relates to the position in sequence of processed nodes, not to the position in the input document. Link to comment Share on other sites More sharing options...
anmarie63 Posted December 11, 2009 Author Share Posted December 11, 2009 Works great. Thank you! Link to comment Share on other sites More sharing options...
anmarie63 Posted December 15, 2009 Author Share Posted December 15, 2009 I think instead of xsl:for-each with a nested xsl:if you simply want <xsl:for-each select="category/attribute[property='private methods']"> and then remove the xsl:if but continue to use the position() function as you have. As I said, it relates to the position in sequence of processed nodes, not to the position in the input document. Can another attribute match be added onto this path?<xsl:for-each select="category/attribute[property=private methods]"> Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.