Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
Reply With Quote
  #2 (permalink)  
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
Reply With Quote
  #3 (permalink)  
Old August 16th, 2007, 12:01 PM
mhkay's Avatar
Wrox Author
Points: 18,438, Level: 59
Points: 18,438, Level: 59 Points: 18,438, Level: 59 Points: 18,438, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,954
Thanks: 0
Thanked 290 Times in 285 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
Reply With Quote
  #4 (permalink)  
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:57 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.