Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2007, 04:51 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default traversing preceding-sibling in reverse doc order

I'm using Oxygen 8.1 and Saxon 8.

I am trying to mine information from a table.

In some cases the cell with the target data is straddled between two or more rows.

So, if I look into the row and the target is not there, I need to look in the row above. If the target is not there, then go up one more. Repeat until the target is found.

I am trying to implement this as a recursive template:
Code:
    <xsl:template match="row" mode="row-proc">
        <xsl:choose>
            <xsl:when test=".//TL1Attribute">
                <xsl:value-of select=".//TL1Attribute"></xsl:value-of>                    
                <xsl:text>#x0A;</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="preceding-sibling::node()[last()]" mode="row-proc"></xsl:apply-templates>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
My reasoning for select="preceding-sibling::node()[last()] is process a selection of the sibling nodes (table rows), going directly to the last() one (should be the row right before the current row???) and recurse into the template.
If the target isn't found then get a new preceding sibling list, get a new last() node and recurse again.

Obviously this isn't working, but I'm not sure why.

It nearly works, except instead of going back one row, it goes all the way back to the first row.

So, what is the best way to process a preceding-sibling list in reverse document order?

Thanks,

- mike



------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
__________________
------------------------
Keep Moving Forward

GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old August 16th, 2007, 09:55 AM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

I seem to have figured it out using select="preceding-sibling::node()[1]. Using [1], it always takes me to the immediately preceding row in the table.

Does preceding-sibling already put the nodes in reverse document order?

Thanks!

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare
 
Old August 16th, 2007, 12:01 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 1.0, for-each and apply-templates always process the selected nodes in document order, regardless how they were selected, even if they were selected using a reverse axis. You can process the nodes in reverse document order using <xsl:sort select="position()" data-type="number" order="descending"/>.

As you've discovered, you can get the nearest preceding sibling using preceding-sibling::*[1].

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 16th, 2007, 01:28 PM
Friend of Wrox
Points: 470, Level: 7
Points: 470, Level: 7 Points: 470, Level: 7 Points: 470, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2004
Location: Plano, TX, USA.
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Thanks Michael

------------------------
GnuPG Key fingerprint = 1AD4 726D E359 A31D 05BF ACE5 CA93 7AD5 D8E3 A876

Michael Hare




Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
Document Order for preceding-sibling mphare XSLT 5 February 22nd, 2007 03:10 PM
preceding-sibling descendant xaun XSLT 3 February 28th, 2006 02:48 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
preceding-sibling after sort rushman XSLT 3 January 18th, 2005 11:08 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.