Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] How to find out if the preceding sibling is a PI

From: David Carlisle <davidc@--------->
To:
Date: 12/2/2005 11:49:00 PM
] Hi all,
] 
] I have a document that looks something like this:
] 
] <?xm-insertion_mark_start author="Nadia Swaby"
] time="20051202T111856-0500"?>
] <design.consideration></design.consideration>
] 
] I need to do a test to find out if the sibling immediately preceding the
] design.consideration element is an xm-insertion_mark_start PI.
] 
] Basically, I need something like
] preceding-sibling::*[position() = 1 and
] processing-instruction('xm-insertion_mark_start')]
] but that statement doesn't return anything.
] 
] Is there any way of doing this?
] 

Yes you just need to be more careful in your natural language
description of the problem, then the xpath follows naturally.
You show three nodes, a PI, a text node with value a newline character,
and an element node with name design.consideration.

preceding-sibling::* selects preceding _elements_ so if teh current node
is the design.consideration element, it won;t select anything (so the
predicate has no effect. If there was an earlier element selected by the
* , the predicate would select the element if it was the first element
(counting backwards) and if it had a _child_ processing instruction.

So I think what you actually want to ask is if the first node (in
reverse order) that is not white space text is a PI owith the name
xm-insertion_.

so
preceding-sibling::node[not(self::text()[normalize-space()=''])]
                       [1]
                       [self::processing-instruction('xm-insertion_mark_start')]

David

________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


transparent
Print
Mail
Like It
Disclaimer
.

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 www.altova.com/list/index.html. 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.

.
.

transparent

transparent