Skip to main content
12-Amethyst
October 25, 2019
Solved

help with ACL function

  • October 25, 2019
  • 1 reply
  • 2657 views

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"

Best answer by GarethOakes

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;
}

1 reply

16-Pearl
October 28, 2019

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 🙂

Darquise12-AmethystAuthor
12-Amethyst
October 29, 2019

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.

 

16-Pearl
October 30, 2019

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;
}