Skip to main content
1-Visitor
December 8, 2016
Solved

How to find an empty attribute in Arbortext?

  • December 8, 2016
  • 2 replies
  • 5290 views

Hello-

I can't get Find/Replace attributes to find attributes that are null (empty).  Is there a trick to that?  Or a way to do it from the command line?  Thank you.

    Best answer by ClayHelberg

    Hi Nancy--

    OK, great. So to answer your follow-up questions:

    1. Yes, to limit the search to specific elements, simply replace "*" in the XPath expression with an explicit tag name. For example, to find <cite.state.law> elements without a ref attribute, you would use: "//cite.state.law[not(@ref)]". (It gets a little trickier if you are using namespaces, but there are ways around that.)
    2. To go to each instance, see my original reply above. The strategies outlined there (via either ACL function or command line commands) should work fine once you get the XPath expression tweaked to collect just the items you are interested in.

    Note that XPath is extremely powerful, and can let you specify complex element constraints. For example, if you wanted to get <cite.state.law> elements with no "ref" attribute, but only if they are inside <cite.state> elements where the "state.name" attribute is "MN", you could do something like this:

         //cite.state[@state.name="MN"]//cite.state.law[not(@ref)]

    So, if you get to know XPath well, you can be very precise in selecting exactly the elements you want (and only those elements). There are plenty of tutorials online to help you learn to use the full power of XPath. A quick Google search should turn up lots of good hits.

    --Clay

    2 replies

    18-Opal
    December 8, 2016

    I had this same question. If you have a support contract with PTC, see https://support.ptc.com/appserver/cs/view/solution.jsp?n=CS109701&art_lang=en&posno=1&q=CS109701&source=search

    In an RDE, you can also enter in the command bar at the bottom :

    find -m "<indexterm><indexterm> " or you can also do find -m "<indexterm></indexterm>" this will search for empty indexterm elements.

    Bryon

    1-Visitor
    December 8, 2016

    Thanks so much for taking the time to respond.  Unfortunately, I can't use that link.  And I think you are showing me how to find empty tags.  I need to find empty attributes.

    For example, I have a user who has 200 footnotes in a document and in most of them, the only.in attribute is set to !print.  (Hence, those footnotes will not appear in the print product; only the electronic product.)  But in a handful of footnotes, the only.in element did not get input so they are blank.  Is there a way he can basically say "take me to each footnote that does not have anything in the only.in attribute?"

    Thanks again.

    18-Opal
    December 8, 2016

    Hi Nancy--

    You can do this via XPath in a script, or you could break it down into multiple command-line steps.

    A script function would look something like this:

    function findEmptyAttributes(attrname) {

    local oids, o;

    xpath_nodeset(oids, "//*[@" . attrname . " = '']");

    for (o in oids) {

       # do something useful here, e.g. remove the empty attr

       oid_delete_attr(oids[o], attrname);

    }

    }

    Or, if you want to use the command line, do something like this:

         xpath_nodeset($oids, "//*[@foo='']");

    This will fill the array $oids with pointers to the elements with empty attribute values for attribute "foo" (adjust as necessary for your desired attribute name). You can see how many hits you got with the count() function:

         response("Found " . count($oids) . " empty attr values");

    Then you can go through the list one by one, referencing it by index in the array. For example, to go to the first hit, use

         goto_oid($oids[1]);

    To go to the second, use goto_oid($oids[2]), and so on.

    --Clay

    1-Visitor
    December 8, 2016

    Embarrassingly, implementing a script is a bit over my head, plus the developers probably wouldn't let me.  I'm just a support person/trainer.

    I tried the command...  

    xpath_nodeset($oids, "//*[@country.code='']");    (country.code being an attribute of <county> I emptied) 


    ...but the response command returned 0 empty elements.  Am I doing something wrong?  Or maybe my system is setup differently?


    Thanks.


    18-Opal
    December 8, 2016

    Hi Nancy--

    Well, the XPath looks OK, assuming you have ruled out misspelling the attribute name. Can you paste a copy of the markup you are trying to match, i.e. the instance you modified with an empty attribute value?

    --Clay