Skip to main content
1-Visitor
May 20, 2014
Question

Which uses least resources?

  • May 20, 2014
  • 8 replies
  • 1786 views

I'm testing for presence of any content in a tag and I'm wondering which is the least expensive, or if there is a better way (I'm using #2)


1. <specval attname="_styleexportfosi::sysfunc_content_test('','#any','atAnyLevel','includes')"&lt;br"/>attloc="system-func" attval="1"/>

2. <specval attname="self::*[normalize-space(.)!="]" attloc="#xpath" attval="1"/">

3. <savetext textid="isEmpty.txt" conrule="#CONTENT"/">
<specval attname="isEmpty.txt" attloc="#FOSI" attval="#ANY"/>


Thanks!

    8 replies

    1-Visitor
    May 21, 2014
    Caroline,



    What are attempting to do? Verify there is content before output or to put
    something there in the output stream?

    If you are just looking to validate missing content, an ACL script might be
    work better. Try this script out.

    Save it to a folder and from the command line type 'source
    path/empty-element.acl'



    You will get a dialog to enter the name of the element you are looking for
    to see if it is empty. Enter the element and click 'ok'. The file will be
    read and the any elements that match the element name and have no content
    (and are not a declared EMPTY element) will be displayed.



    You can tweak this further to give you the context and a possible location
    in the file. This is just a quick script to find any empty elements of a
    specific name may be in the document.

    Lynn




    1-Visitor
    May 21, 2014
    I can't provide any information about the relative cost, performance-wise,
    of those three methods. I do not think #2 is one of the soul-crushing
    performance hounds that will bring your server to its knees. Especially if
    the element being tested is not extremely common, Because #2 is looking at
    the element already in memory, it should not be "bad". It's when you start
    doing things like \para\@attr where the entire tree is examined every time
    that you can get in trouble.

    FYI: I do not think #3 will do what you want. I think isEmpty.txt will
    always satisfy #ANY whether or not there is content in the element because
    isEmpty.txt will always be instantiated (which is what #ANY tests) even if
    it is in fact empty. You could write an ACL that evaluated the
    non-white-space beginning/ending string length and returned 0 for zero
    length and 1 for anything else and call it from a sys-func. Again, though,
    I'm not sure how that would compare to #2 performance-wise.


    <specval attname="packagename::aclname" attloc="system-func" attval="0">
    Or
    <specval attname="packagename::aclname" attloc="system-func" attval="1">

    where your ACL file looks like this (typed by hand, so test/debug before
    you use it):

    ####
    package packagename
    function aclname(win,oid) {
    local exists = 0
    if (length(trim($oid)) > 0 {
    exists = 1
    } # end if
    return $exists
    } # end aclname
    ####

    On Tue, May 20, 2014 at 9:39 AM, Caroline Leccese <
    -> wrote:

    > I'm testing for presence of any content in a tag and I'm wondering which
    > is the least expensive, or if there is a better way (I'm using #2)
    >
    > 1. <specval<br/>> attname="_styleexportfosi::sysfunc_content_test('','#any','atAnyLevel','includes')"
    > attloc="system-func" attval="1"/>
    >
    > 2. <specval attname="self::*[normalize-space(.)!="]" attloc="#xpath"&lt;br"/>> attval="1"/>
    >
    > 3. <savetext textid="isEmpty.txt" conrule="#CONTENT"/">
    > <specval attname="isEmpty.txt" attloc="#FOSI" attval="#ANY"/>
    >
    > Thanks!
    >
    1-Visitor
    May 21, 2014
    I have attached PDF from my book on How to determine if an element has content. There is more than one way to do it, including the use of SYSTEM-FUNC, depending on what you're trying to do.

    Good Luck!
    Suzanne Napoleon
    www.FOSIexpert.com
    "WYSIWYG is last-century technology!"


    cleccese1-VisitorAuthor
    1-Visitor
    May 22, 2014

    Thanks, everyone!


    In general, ACL is cheaper than XPATH? I usually only need to check one child, sibling or parent, i.e. using [1] not //

    1-Visitor
    May 22, 2014
    Caroline,



    Did we help you or just confuse you more?

    Lynn


    1-Visitor
    May 22, 2014
    I'm confused! But then that's easy to do.
    1-Visitor
    May 22, 2014
    For the record, the reason #3 doesn't work is because #FOSI is used in the same e-i-c as the savetext to the variable being tested (same is true for enumerating a counter). The savetext/enumerate needs to be in a different e-i-c, or the specval with #FOSI needs to be in a pseudo-element.

    3. <savetext textid="isEmpty.txt" conrule="#CONTENT"/">
    <specval attname="isEmpty.txt" attloc="#FOSI" attval="#ANY"/>


    Suzanne


    cleccese1-VisitorAuthor
    1-Visitor
    May 22, 2014



    In Reply to Lynn Hales:


    Caroline,



    Did we help you or just confuse you more?

    Lynn