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 March 1st, 2007, 05:16 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default Preceding-sibling question.

Hello,

I did check my book (XSLT 2.0) before posting and I thought I understood the preceding-sibling function which appears on pages 77 & 763.

I want to check to see if the sibling above the context node has a certain value.

Below is what I tried:

preceding-sibling::*/@eol
preceding-sibling::/@eol

Neither of these work, I wasn't sure about how to attack this one. I thought maybe someone ran across this before. Thanks for your time.

 
Old March 1st, 2007, 05:19 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I think I figured it out guys, thanks.

preceding-sibling::*[1]/@eol

 
Old March 1st, 2007, 05:31 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quick question if anyone read my earlier post I want to add to my original statement and check for a eol attribute (@eol) and see if the preceding-sibling is not a 'TXT' element.


This is my attempt:

<xsl:when test="preceding-sibling::*[not(name() = 'TXT')]/@eol">


Anyone come across this one?

 
Old March 1st, 2007, 07:26 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

This:

preceding-sibling::/@eol

is a syntax error. You can't leave out the node-test.

This:

preceding-sibling::*/@eol

selects the @eol attribute of all the preceding siblings. In a boolean context, it returns true if any preceding sibling has an @eol attribute.

I suspect you want

test="preceding-sibling::*[1]/@eol"

which tests whether the immediately preceding sibling has an @eol attribute.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 1st, 2007, 07:27 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

This:

preceding-sibling::*[not(name() = 'TXT')]/@eol

tests whether there is a preceding sibling whose name is not TXT and that has an eol attribute. I think you want

preceding-sibling::*[1][not(self::text)][@eol]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 5th, 2007, 11:55 AM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

mhkay,

Can I ask you one more quick question.

I have the following:

preceding-sibling::*[1][. != '']

Which finds the first non empty sibling this works great for most of my code but anytime the node whose previous sibling has attributes on it (i.e. @something) it never finds that node with the above statement (preceding-sibling::*[1][. != '']) Just wondering if you had any input.

 
Old March 5th, 2007, 12:20 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

Then perhaps you want

preceding-sibling::*[1][. != '' or @*]

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 5th, 2007, 12:35 PM
Authorized User
 
Join Date: Jul 2006
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you.





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 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.