General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Elliminating spurious ws chars within Xpath predicate
-
russurquhart1 April 15, 2009 at 2:13 pm
Elliminating spurious ws chars within Xpath predicate
April 15, 2009 at 2:13 pmParticipants 1Replies 2Last Activity 13 years, 11 months agoHi,
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[1]”);
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[1]”);
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?
Thanks,
Russ
dcramer April 15, 2009 at 2:53 pm
Reply to: Elliminating spurious ws chars within Xpath predicate
April 15, 2009 at 2:53 pmYou 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).David
russurquhart1 April 15, 2009 at 3:21 pm
Reply to: Elliminating spurious ws chars within Xpath predicate
April 15, 2009 at 3:21 pmActually 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!!
Thanks,
Russ
-
AuthorPosts
- You must be logged in to reply to this topic.