General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Elliminating spurious ws chars within Xpath predicate

  • russurquhart1

    Elliminating spurious ws chars within Xpath predicate

    Participants 1
    Replies 2
    Last Activity 13 years, 11 months ago

    Hi,

    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

    Reply

    dcramer

    Reply to: Elliminating spurious ws chars within Xpath predicate

    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).

    David

    Reply

    russurquhart1

    Reply to: Elliminating spurious ws chars within Xpath predicate

    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!!

    Thanks,

    Russ

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support