[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Filtering Problem using position()

Subject: RE: Filtering Problem using position()
From: "Schwartz, Rechell R, ALCAS" <rrschwartz@xxxxxxx>
Date: Fri, 8 Nov 2002 13:27:28 -0500
xslt odd even position
Ken,

I am impressed! This is what I was looking for!

Thanks,
Rechell

-----Original Message-----
From: G. Ken Holman [mailto:gkholman@xxxxxxxxxxxxxxxxxxxx] 
Sent: Friday, November 08, 2002 12:55 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Filtering Problem using position()

At 2002-11-08 12:22 -0500, Schwartz, Rechell R, ALCAS wrote:
>I still need to copy those rows that don't need to have the odd/even
row
>styles applied to them.

Gee!  Why didn't you say that the first time? :{)}

>Do I need to set up a separate template rule for
>the filtered out nodes?

Nope ... undo what I told you last time, since you are still working
with 
all of the rows.

In this case I don't think position() is going to help you ... I suggest

using count() as below.

It is important when working with XSLT to know that sometimes you need
to 
approach problems without always using matching.  Other tools are
available 
to examine the source node tree.

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:choose>
     <xsl:when test="count( preceding-sibling::tr[td[not(a)  and 
not(@class)]] )
                     mod 2 = 1">
     <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><a></a></td>
       </tr>

       <tr>
          <td class="oddRowStyle">good</td>
       </tr>

       <tr>
          <td><a></a></td>
       </tr>

       <tr>
          <td class="evenRowStyle">good</td>
       </tr>

       <tr>
          <td class="oddRowStyle">good</td>
       </tr>

       <tr>
          <td><a></a></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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.