General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Searching for matching attribute values. Xpath the best way?

  • russurquhart1

    Searching for matching attribute values. Xpath the best way?

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

    Hi,

    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; i                  var 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

    Reply

    Derek Read

    Reply to: Searching for matching attribute values. Xpath the best way?

    I 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);

    Reply

    russurquhart1

    Reply to: Searching for matching attribute values. Xpath the best way?

    Ah!  Thanks! That did the trick!

    Russ

    Reply

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

Lost Your Password?

Products
Downloads
Support