General XMetaL Discussion
russurquhart1 April 15, 2009 at 2:13 pm
Elliminating spurious ws chars within Xpath predicateApril 15, 2009 at 2:13 pmParticipants 1Replies 2Last Activity 13 years, 7 months ago
After you pointed out how to use Xpath to select nodes for a node list, things have been great, or so i thought.
I am executing the following to get a node list:
var nodelist = ActiveDocument.getNodesByXPath(“//row/entry[Emphasis = 'Address Offset']/ancestor::row/following-sibling::row/entry[Emphasis = 'Physical Address']/following-sibling::entry[Emphasis = 'Instance']/ancestor::GenTable”);
In my test files, this worked, on another file, it fails to return any GenTable elements, even though i know there are elements that match this.
To test this, i just used:
var nodelist = ActiveDocument.getNodesByXPath(“//row/entry[Emphasis = 'Instance']/ancestor::GenTable”);
And this returned the expected GenTable elements. I think that there are spurious ws characters between the words of “Address Offset” and “Physical Address” that are causing the elements to not be found.
Is there a way to eliminate those, within this Xpath expression, and still get a nodelist?
Russdcramer April 15, 2009 at 2:53 pm
Reply to: Elliminating spurious ws chars within Xpath predicateApril 15, 2009 at 2:53 pm
You mean you have whitespace in the Emphasis element, like
Instance… and so your predicate [Emphasis = 'Instance'] isn't matching it? You could do [normalize-space(Emphasis) = 'Instance']. The normalize-space() function strips leading and trailing whitespace (and collapses multiple whitespaces characters inside the string).
Davidrussurquhart1 April 15, 2009 at 3:21 pm
Reply to: Elliminating spurious ws chars within Xpath predicateApril 15, 2009 at 3:21 pm
Actually the spurious characters were cropping up, in the Emphasis element, but when the value was either “Adress Offset” or “Physical Address”, the only instances where there WAS at least one ws character.
In either case, that did the trick!!
- You must be logged in to reply to this topic.