General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Searching for matching attribute values. Xpath the best way?
-
russurquhart1 January 7, 2010 at 5:54 pm
Searching for matching attribute values. Xpath the best way?
January 7, 2010 at 5:54 pmParticipants 1Replies 2Last Activity 13 years, 2 months agoHi,
I think i have a little info that can be dangerous.
I am trying to find if there are any Pointer attribute values, for any element, that do NOT have a matching Target attribute value, for any given element. I currently have the following:
ActiveDocument.FormattingUpdating = false;
var href_nodelist = ActiveDocument.getNodesByXpath(“//*[@Pointer]”);
var nodecount = href_nodelist.length;
Application.Alert(“href count is ” + nodecount);
for (i=0; ivar item = href_nodelist.item(i);
var item_val = item.getAttribute(“Pointer”);
Application.Alert(“node is: ” + item_val);
var target_nodelist = ActiveDocument.getNodesByXpath(“//*[@Target=item_val]”);
Application.Alert(“length is: ” + target_nodelist.length);
if (target_nodelist.length == 0)
{
Application.Alert(“Target not found in this document: ” + i + ” – ” + item_val);
}
}
ActiveDocument.FormattingUpdating = true;The target_nodelist.length never seems to get beyond 0, is the preceeding xpath command not valid?
Thanks for any help!
Russ
Derek Read January 7, 2010 at 8:02 pm
Reply to: Searching for matching attribute values. Xpath the best way?
January 7, 2010 at 8:02 pmI think you want to find all elements with an attribute called Target that have the value set in the item_val variable, right? If that's right then you probably want to replace this line:
var target_nodelist = ActiveDocument.getNodesByXpath("//*[@Target=item_val]");
…with something like this:
var target_attr_xpath = '//*[@Target="' + item_val +'"]';
var target_nodelist = ActiveDocument.getNodesByXpath(target_attr_xpath);russurquhart1 January 7, 2010 at 8:59 pm
Reply to: Searching for matching attribute values. Xpath the best way?
January 7, 2010 at 8:59 pm -
AuthorPosts
- You must be logged in to reply to this topic.