Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 March 3rd, 2009, 03:40 PM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default Preceding Sibling

I'm using Saxon 9

I'm parsing a table structure. On a particular row, I may decide I need to look at information on the preceding row.

So, I have a template that processes the table by rows.

I set a var $row to the current row and read a value like $row//Name

if the value of Name is of particular interest, like empty, I look for it on the preceding row

I'm trying $row/preceding-sibling//Name and I'm not getting a value.
Am I using this expression correctly?


[EDIT]

No, I'm not.. I needed $row/preceding-sibling::row[1]//Name and it works just fine.

Thanks,

- m
__________________
------------------------
Keep Moving Forward

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

Michael Hare

Last edited by mphare; March 3rd, 2009 at 03:44 PM..
 
Old March 3rd, 2009, 10:12 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

No, preceding-sibling is an axis so you must specify the element (in this case) as well. I can't believe you didn't get an error rather than just no output:
Code:
$row/preceding-sibling::row//Name
or:
Code:
$row/preceding-sibling::row[1]//Name
if you want the first preceding-sibling.
But not sure why you need //Name rather than /Name, what is the structure of the XML?
__________________
Joe
http://joe.fawcett.name/
 
Old March 4th, 2009, 10:32 AM
Friend of Wrox
 
Join Date: May 2004
Posts: 109
Thanks: 18
Thanked 0 Times in 0 Posts
Default

I need //Name because Name is not a direct child of row. There is a cell element inbetween. I guess I could have gone with /cell/Name, but it didn't seem necessary.


I was not getting an error because I had originally mispelled preceding-sibling as preceeding-sibling, so the parser didn't know it was supposed to be an axis. Once I added the ::row, the parser immediatly errored telling me preceeding-sibling was not a valid axis. Once I fixed that, everything else fell into place. This is when I added the [EDIT] to the original post.

Thanks for the help.
__________________
------------------------
Keep Moving Forward

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

Michael Hare
 
Old March 4th, 2009, 11:04 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

That makes sense. Normally it is better to use the full path rather than // as the latter is an expensive operation.
__________________
Joe
http://joe.fawcett.name/





Similar Threads
Thread Thread Starter Forum Replies Last Post
preceding-sibling::comment() bonekrusher XSLT 11 October 1st, 2008 11:38 AM
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
Preceding-sibling question. lafilip XSLT 7 March 5th, 2007 12:35 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
sorting and preceding-sibling iamhigh XSLT 5 August 25th, 2003 12:23 AM





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