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

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

help with ACL function

Darquise
11-Garnet

help with ACL function

I have an acl function that counts the xref's and resolves the marker. However, it only goes up as high as 26 (a-z), but we have 30+ fn's. Therefore, after z, it needs to restart with ab, ac, ad etc. I hope that makes sense.

 

So we have in the function the following line:

$enumerator = chr(96 + positionWithin($destOid, $scopeOid));

for which i assume is what does the counting. I need to pass a count as $intValue and return a label in the form "a, b, c, ..., aa, ab, ac"

1 ACCEPTED SOLUTION

Accepted Solutions

Just a minor error where the ACL language is similar to Perl and uses . operator for concatenation instead of +. You can test my updated function below from Arbortext command line via response( convert(123) ) or whatever number you like.

 

function convert ($number) {
$str = '';
while($number > 0) {
$number--;
$str = chr($number % 26 + 97) . $str;
$number = $number / 26;
}
return $str;
}

View solution in original post

4 REPLIES 4

I don't think this function is built-in to ACL, but you can implement your own function that is an enhanced version of what you have shown. The current code is using chr() to map an index number to a letter the reason for the 96 is due to the offset into the Unicode/ASCII character table - 97 is the lowercase "a", 98 is "b", etc. The OID stuff is just finding which footnote (first = 1, second = 2, etc.) - positionWithin() is what gives the index number that is added to 96.

If you struggle to imagine how to improve on that approach, then my recommendation would be to study how others have achieved this in other languages, then convert to ACL. Here is a PHP implementation: https://stackoverflow.com/questions/5554369/php-how-to-output-list-like-this-aa-ab-ac-all-the-way-to-zzzy-zzzz-zzzza

I think this could be a small, fun exercise if you have any interest in learning coding! Others may come back with a full implementation for you but I think you should take up the challenge 🙂

Thank you - this information was very helpful. With the help of one of our developers (new to acl) helped with this function, however, now I get 0's everywhere.

function convert($number) {
local str;
while(number) {
$str = chr(($number-1) % 26 + 96) + str;
$number = ($number-1) / 26;

}
return $str;
}

 

Then I call the function at this line:

$enumerator = convert(positionWithin($destOid, $scopeOid));

 

I get the following errors:

[A11276] Badly formed number "`" in expression
(at line 583 of file "\\APEDEV2017\DITA_Custom\custom\scripts\modifyvdoc.acl")
Function traceback at time of error:
#1 ModifyVdoc::convert(number=1) at "\\APEDEV2017\DITA_Custom\custom\scripts\modifyvdoc.acl":583
#2 ModifyVdoc::handleFnXref(rdsDoc=1854, scopeTag="table") at "\\APEDEV2017\DITA_Custom\custom\scripts\modifyvdoc.acl":689

 

If I change 96 to 97, I get Badly formed number "a" in expression.

The handlefnXref resolves the xrefs in the rds. Basically adding, a, b, c, d etc. But with the convert function I get 0's everywhere.

 

Just a minor error where the ACL language is similar to Perl and uses . operator for concatenation instead of +. You can test my updated function below from Arbortext command line via response( convert(123) ) or whatever number you like.

 

function convert ($number) {
$str = '';
while($number > 0) {
$number--;
$str = chr($number % 26 + 97) . $str;
$number = $number / 26;
}
return $str;
}

This great! It works beautifully. I had to make one change:

instead of $str=";

I changed it back to local=str (not sure how all this works, but it worked).

 

Below is the working function:

function convert ($number) {
local str;
while($number > 0) {
$number--;
$str = chr($number % 26 + 97) . $str;
$number = $number / 26;
}
return $str;
}

 

Thank you very very much for you help. Much appreciated 🙂

Top Tags