[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
RE: [xsl] Filtering Problem using position()
Subject: RE: [xsl] Filtering Problem using position() From: "Schwartz, Rechell R, ALCAS" <rrschwartz@xxxxxxx> Date: Fri, 8 Nov 2002 12:22:16 -0500 |
Ken, I still need to copy those rows that don't need to have the odd/even row styles applied to them. Do I need to set up a separate template rule for the filtered out nodes? Thanks, Rechell -----Original Message----- From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] Sent: Friday, November 08, 2002 12:08 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Filtering Problem using position() At 2002-11-08 11:48 -0500, Schwartz, Rechell R, ALCAS wrote: >However, the styling is based on odd and even rows in the stylesheet,and >it seems that it is applying the calculation of the position() to >INCLUDE those rows that I had excluded when I did a template match. Yes, because the identity transform is processing all of the children of all of the elements, the position() when matching on tr is reflecting the position in relation to the parent. >Any help would be appreciated. Add a template rule one higher in the hierarchy than your test, and then only apply the children you want matched. When they are matched, the position() reflects the desired selection. You don't say what you want done with the tr constructs that don't match your expression ... I'm assuming to ignore them. The more you add to the stylesheet the more you will need to consider if priority is required ... it isn't yet, but keep it in mind. You don't give any test data, but I think what I have below works for you. I only added one template rule. I hope this helps. .............. Ken T:\ftemp>type rechell.xml <?xml version="1.0" encoding="iso-8859-1"?> <test> <table> Nothing here </table> <table> <tr><td><a></a></td></tr> <tr><td>good</td></tr> <tr><td><a></a></td></tr> <tr><td>good</td></tr> <tr><td>good</td></tr> <tr><td><a></a></td></tr> <tr><td>good</td></tr> </table> <table> Nothing here as well </table> </test> T:\ftemp>type rechell.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html" indent="yes"/> <xsl:template match="node()|@*"> <!--identity transform--> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <xsl:template match="table[2][tr[td[not(a) and not(@class)]]]"> <xsl:copy> <xsl:apply-templates select="tr[td[not(a) and not(@class)]]"/> </xsl:copy> </xsl:template> <xsl:template match="table[2]/tr[td[not(a) and not(@class)]]"> <xsl:copy> <xsl:choose> <xsl:when test="position() mod 2 = 0"> <xsl:for-each select="td"> <td class="evenRowStyle"> <xsl:apply-templates select="node()|@*"/> </td> </xsl:for-each> </xsl:when> <xsl:otherwise> <xsl:for-each select="td"> <td class="oddRowStyle"> <xsl:apply-templates select="node()|@*"/> </td> </xsl:for-each> </xsl:otherwise> </xsl:choose> </xsl:copy> </xsl:template> </xsl:stylesheet> T:\ftemp>saxon rechell.xml rechell.xsl <test> <table> Nothing here </table> <table> <tr> <td class="oddRowStyle">good</td> </tr> <tr> <td class="evenRowStyle">good</td> </tr> <tr> <td class="oddRowStyle">good</td> </tr> <tr> <td class="evenRowStyle">good</td> </tr> </table> <table> Nothing here as well </table> </test> T:\ftemp>rem Done! -- Upcoming hands-on in-depth XSLT/XPath and/or XSL-FO: - North America: Feb 3 - Feb 7,2003 G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (F:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 0-13-140374-5 Definitive XSL-FO ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-10-1 Practical Formatting Using XSL-FO Next conference training: 2002-12-08,03-03,06 XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Filtering Problem using p, G. Ken Holman | Thread | RE: [xsl] Filtering Problem using p, G. Ken Holman |
Re: [xsl] Filtering Problem using p, David Carlisle | Date | RE: [xsl] Any recommended XSLT book, Max Dunn |
Month |