cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X

Which uses least resources?

cleccese
10-Marble

Which uses least resources?

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 8

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




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

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


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

Caroline,



Did we help you or just confuse you more?

Lynn


I'm confused! But then that's easy to do.

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




In Reply to Lynn Hales:


Caroline,



Did we help you or just confuse you more?

Lynn

Announcements

Top Tags