p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   XSLT (http://p2p.wrox.com/forumdisplay.php?f=86)
-   -   Preceding-sibling question. (http://p2p.wrox.com/showthread.php?t=54775)

lafilip March 1st, 2007 05:16 PM

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.


lafilip March 1st, 2007 05:19 PM

I think I figured it out guys, thanks.

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


lafilip March 1st, 2007 05:31 PM

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?


mhkay March 1st, 2007 07:26 PM

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

mhkay March 1st, 2007 07:27 PM

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

lafilip March 5th, 2007 11:55 AM

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.


mhkay March 5th, 2007 12:20 PM

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

lafilip March 5th, 2007 12:35 PM

Thank you.



All times are GMT -4. The time now is 01:02 PM.

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