Altova Mailing List Archives
>comp.text.xml Archive Home
>Thread Prev - XSLT: selecting nodes matching either of 2 criteria
>Thread Next - Re: XSLT: selecting nodes matching either of 2 criteria
Re: XSLT: selecting nodes matching either of 2 criteria
Date: 7/30/2007 12:23:00 PM
In article <Gbkri.38748$%v3.16766@f...>, Andy Fish <ajfish@b...> wrote: >I am trying to determine whether the preceding sibling (ignoring anything >other than nodes or comments) is a comment. in procedural terms it's: "Other than nodes"? Everything's a node. Did you mean "other than elements" (as the "*" later suggests)? >for each preceding sibling > if (node type is node or comment) > return (node type = comment) > end if >end loop Again, do you really mean "node type is node"? Surely "node type is element"? >the first step seems to be to list the preceding siblings which are either >nodes or comments, but this doesn't work: > > <xsl:if test="preceding-sibling:*|comment()"> > >because the | has too high a priority, and I can't use brackets like this: > > <xsl:if test="preceding-sibling:(*|comment())"> Apart from the priority, this is testing the wrong thing. You can correct the priority by changing it to preceding-sibling::*|preceding-sibling::comment() but that tests whether the node *has* a preceding sibling that's an element or comment. My guess is that you want to know, of the preceding siblings that are elements or comments, whether the nearest one is a comment. If so, then you might try (preceding-sibling::*|preceding-sibling::comment())[self::comment()] *WRONG* but that won't work, because though "" means first in the backwards direction for preceding-sibling, it doesn't mean that for a parenthesized expression - it means first in document order. In fact you want (preceding-sibling::*|preceding-sibling::comment())[last()][self::comment()] or preceding-sibling::node()[self::*|self::comment()][self::comment()] -- Richard -- "Consideration shall be given to the need for as many as 32 characters in some alphabets" - X3.4, 1963.