Altova Mailing List Archives

Re: XSLT: selecting nodes matching either of 2 criteria

From: richard@------.--.--.-- (------- -----)
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

>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


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

   (preceding-sibling::*|preceding-sibling::comment())[1][self::comment()]  *WRONG*

but that won't work, because though "[1]" 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


-- Richard
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.