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

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

savetext value with leading zeros and FOSI

kmccain
3-Newcomer

savetext value with leading zeros and FOSI

Hi,


I am creating a print fosi for our tech authors to review content in a pdf form.


I have an element that requires a 3-digit numerical value per its DTD (which I can't alter) and am capturing its value with a savetext in order to output it later in the instance. That was fine, but now my authors want to see that number output without its leading zeros when they print a review copy if its value is less than 100, i.e., "98" not "098". Is there a way to strip those leading zeros out using FOSI?


Thanks, KM

19 REPLIES 19

I do the reverse using a system-func. I need an article number that is
padded with zeros that may be entered as 2 digits. For example, I need 0098
not 98.

This is the FOSI fragment:
<att>
<fillval attname="myacl::myfunc" attloc="system-func" fillcat="savetext"&lt;br"/>fillchar="conrule">
<charsubset>
<savetext textid="mysavetextvar.txt">
</charsubset>
</att>

This is the system function (place it in an ACL in Publishing Engine's
custom\editinit subfolder or your editinit if you're composing locally):

Filename: myacl.acl

package myacl

function myfunc(win, oid) {
return reverse(substr(reverse('0000' .
oid_xpath_string($oid,'count(preceding-sibling::article)')),1,4);
} # end myfunc

Notes:
1) Hand typed. May contain typos! Anyhow, your function will have to be
different anyhow since you're doing the opposite.
2) Calls to system-funcs can degrade performance. In my environment, this
is not a "bad" one. Some, however, can geometrically increase processing
time ... if you search the adepter e-mail archives, we've talked about this
before and, I think, listed some types of system-func behavior that will do
this.






On Tue, Sep 24, 2013 at 7:35 AM, Kim McCain
<kmccain@triaddesignservice.com>wrote:

> Hi,
>
> I am creating a print fosi for our tech authors to review content in a pdf
> form.
>
> I have an element that requires a 3-digit numerical value per its DTD
> (which I can't alter) and am capturing its value with a savetext in order
> to output it later in the instance. That was fine, but now my authors want
> to see that number output without its leading zeros when they print a
> review copy if its value is less than 100, i.e., "98" not "098". Is there a
> way to strip those leading zeros out using FOSI?
>
> Thanks, KM
>

Hi Kim,

If I correctly understand what you want to do,FOSI alone cannot strip anything from content. You will need to code SYSTEM-FUNC in a FOSI att to call an ACL function that uses substr to strip any leading zeroes and returns the result to a FOSI savetext or usetext.

The ACL experts in this group can provide more detail if necessary.

Good luck!

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




Paul,

If I correctly understand what you are doing, check out the padlen characteristic on the counter category.

Suzanne


Okay, CAVEAT EMPTOR.



What is worse, is I am thinking out loud.

I think Susanne is pretty close to right. Here is the gist of what I think
MIGHT (see the first line of the email) work.

Save the content of the three character element to a string (FOSI can do
this)

Use a SYSTEM-FUNC to run an ACL function that will strip the leading zero's
(there is a substring function that utilizes regular expressions that can do
this)

Save the truncated string back to a string (not sure if you want to save it
back to the original or use a new string variable name here, but I think a
new string would be best)

Output the string through a <usetext>

Lynn


kmccain
3-Newcomer
(To:kmccain)

Hi again and thanks for the suggestions.


Unfortunately, I have never delved into ACL and I think I may need a wee more help. I looked up the substr function in the Arbortext Helpcenter reference, but that expects me to know where to chop the string and I can't know that since there could be either one or two leading zeros in the string. I think that the sub function is probably the right one since it says it allows regular expressions as Lynn suggested, but I confess I have no idea how to put such a script together and feed the result back to my FOSI.


So I'm guessing I need to learn ACL. Is there some place that shows you practical examples of how to put together an ACL script? I didn't find too many helpful examples in Helpcenter, or maybe I just don't know how to search for them well. Any good books on it?


KM

Kim,



What I would do is make a short ACL script that would have to 'if'
statements. One for a single leading zero, the other for two leading zeros
(which would be the first test). I am no programmer by any means, but I
found ACL fairly easy to work with.

A simple ACL script would look something like this:

function unique_function_name ()

{

Your tests go in here. A "#" is a commented line.



}

Here is a simple ACL script that goes through an XML file and counts the
number of times a specific element is used. I include this because it shows
you how to traverse your file (the 'while(oid_valid)'). And it shows how to
use an 'if' statement.



You might want to look at the 'substitute' function (help 9051) as well as
the 'substr' function. I'd first test for



If(substr($stringwithyournumber, 1, 2)=="00")

{the action to truncate the zero's}

Else

{the action to truncate the single zero}



function element_count ()

{
#this line allows you to enter the element name and it is stored in variable
'elname'

readvar -prompt "Enter the element to count." elname;



#This line set variable 'o' to be the first oid in the file to be tested

o=oid_first();
#This sets a counter variable 'count' to count the times the desired element
is used

count=0;



#this is the segment that allows the file to be traversed.

#as long as there is a valid oid, the rest of the script will process.

while (oid_valid(o));
{
#This reads the name of each oid and test for a match to the element name
variable

if(oid_name(o)=="$elname")

{
#if the element name matches then the counter is incremented

count++
}
#This moves the process forward to the next oid in the file

o=oid_forward(o);
}
#This returns a dialog box with the number of times the desired element was
used.

response("There are $count <$elname> elements in the document.")
}





You will need to save the file and then 'source' it (only have to do that
once each Epic startup, then it is memory resident). You would call the
function by typing the function name (with the parens) in the command line.
One note in naming the function, the parens have a space between the end of
the name, when calling the function, there is no space

function function_name ()
calling function_name()



Hope this helps a bit.



Lynn




ajordin
4-Participant
(To:kmccain)

Kim,

The following acl function should do what you want...

function stripzero(wid, oid) {
local x, i, val
$x = oid_content(oid)
$i = match($x, '[^0]')
$val = substr($x, $i)
return $val
}

I've written this to be called from the fosi which will send the arguments 'wid' and 'oid' automatically.
This should be called from the element containing the number to be processed.

The function uses a regular expression to get the position of the first character that isn't a zero and substrings from there, retuning the new value.
If you want to test this, save the above in a text file, eg 'zero.acl' in the \scripts folder of your Arbortext \custom directory.
open a document in Arbortext and place the cursor in an element containing a number to be processed.
On the Arbortext command line type the following and press Enter to load the script, (you only need to do this once per session)
source zero.acl
Then on the command line type the following and press Enter to call the function
eval stripzero($w, oid_current_tag())


ACL isn't difficult to learn, by the way. You don't need to be a high level programmer or even pretend to be one.

Adrian Jordin - Senior Consultant
Mekon Ltd.
intelligent content solutions
e adrian.jordin@mekon.com<|">mailto:adrian.jordin@mekon.com>| t +44 (0)117 303 5202 | m +44 (0)7515294338| w www.aerospace-defence.com<">http://www.aerospace-defence.com>

Todays content needs agility - www.congility.com

Hi Kim,

More info on and some examples of SYSTEM-FUNC are in "Rules of the Road," a chapter from my book on FOSI. The chapter is available at
kmccain
3-Newcomer
(To:kmccain)

Adrian,


First of all, thanks. I did give your acl script a try, but it does not work for my situation.


It works if the text content is in the element itself, but my content is actually the value of an attribute that I am capturing with a savetext in my FOSI. I need to strip the zeros out of that saved string to a new value before outputting it later on the page.


So I am going to play with this a bit more I guess.

ajordin
4-Participant
(To:kmccain)

KIm,

if you need to handle an attribute then replace oid_content with oid_attr, ie
$x = oid_attr(oid, 'attrname')
replacing attrname with the name of your attribute, (keep the quotes).

You can call this with an attribute rule which will put the result into a savetext.

<att>
<fillval attname="stripzero" attloc="system-func" fillcat="savetext"&lt;br"/>fillchar="conrule">
<charsubset>
<savetext textid="test.txt"></charsubset>
</att>


Adrian Jordin - Senior Consultant
Mekon Ltd.
intelligent content solutions
e adrian.jordin@mekon.com<|">mailto:adrian.jordin@mekon.com>| t +44 (0)117 303 5202 | m +44 (0)7515294338| w www.aerospace-defence.com<">http://www.aerospace-defence.com>

Todays content needs agility - www.congility.com
kmccain
3-Newcomer
(To:kmccain)

Thanks again for your input. I followed your instructions - I updated my acl script as you suggested and added an attribute rule (to call the script and do the savetext) to the e-i-c for the element that has the attribute with the value I'm trying to modify - but I still have no success.


I now get no value at all when I output the text string later in the page. So I guess I'm still doing something wrong. I suspect I'm just not getting the value of the attribute into the function properly to begin with. Is there a way to check the function at the command line like you suggested in the previous one?

ajordin
4-Participant
(To:kmccain)

KIm,

you can test the function in the same way as before;
source the file
source zero.acl
then place your cursor in the element to be processed and on the Arbortext command line type the following and press enter...
eval stripzero($w, oid_current_tag())

If that doesn't return a value, then the problem is in the function itself.
If this returns the correct value then..
- on the eic for the element, add a usetext (placement = after) that outputs the savetext together with a text string, eg
<usetext source="\" **=" \,num.txt&quot;=" placemnt="after"></usetext>

You should see '**' followed by the number output at the end of the element.
If it is then the problem is with the output of the save text later in the document, if not then it's a problem with the attribute rule or savetext.


Adrian Jordin - Senior Consultant
Mekon Ltd.
intelligent content solutions
e adrian.jordin@mekon.com<|">mailto:adrian.jordin@mekon.com>| t +44 (0)117 303 5202 | m +44 (0)7515294338| w www.aerospace-defence.com<">http://www.aerospace-defence.com>

Todays content needs agility - www.congility.com

Try fillvaling into a usetext source to see what the system-func is returning.

Suzanne


kmccain
3-Newcomer
(To:kmccain)

Thank you for your help again. I'm getting closer at least. I confirmed that the function is doing its thing correctly by opening my test file and sourcing the script (zero.acl - below) and using the eval command. It pops up a box with the truncated number. So that's good.


function stripfigno(wid, oid) {
local x, i, val
$x = oid_attr(oid, 'figureNumber')
$i = match($x, '[^0]')
$val = substr($x, $i)
return $val
}


There is a problem with the savetext, though, because when I put a usetext in the element with the attribute rule as you suggested all I get for output is the random text - ** and then nothing. My attribute rule is:


<att>
<fillval attname="stripfigno" attloc="system-func" fillcat="savetext" fillchar="conrule">
<charsubset><savetext conrule="ipdfigno.txt"></charsubset>
</att>


When I open my file that I am using to test I am also getting this warning:


"Att match: no user defined function named "stripfigno". This is a FOSI coding or application ACL error."


As I said in the beginning, I'm not very familar with ACL so is there something else I need to do in the fosi so it knows how/where to find the function?


Right now, I have the script in my custom\scripts directory as you suggested, but ultimately I would like to be able to put multiple functions into an instance.acl file and keep it in the central custom folder with the dtd and fosi rather than copy scripts to all the writers C: drives. So that's where I'm trying to head.

Just a quick glance, I think your conrule for your savetext should be the return of stripfigno. Ipdfigno.txt looks to be the savetext id?

As for the FOSI warning, did you put the ACL file with this code in the custom\init so it loads on startup? The function must be loaded and available prior to the FOSI loading, so putting this in scripts or editinit may not load the function in time.
ajordin
4-Participant
(To:kmccain)

Kim,

the problem is the second part of the attribute rule. You put the savetext name in the construction field.
Try the following...

<att>
<fillval attname="stripfigno" attloc="system-func" fillcat="savetext"&lt;br"/>fillchar="conrule">
<charsubset>
<savetext textid="ipdfigno.txt"></charsubset>
</att>


Adrian Jordin - Senior Consultant
Mekon Ltd.
intelligent content solutions
e adrian.jordin@mekon.com<|">mailto:adrian.jordin@mekon.com>| t +44 (0)117 303 5202 | m +44 (0)7515294338| w www.aerospace-defence.com<">http://www.aerospace-defence.com>

Todays content needs agility - www.congility.com

Kim,

The error message means the function had not been sourced when formatting began. For testing purposes, you can use the ACL source command at the command line to read in the file with the ACL function, or you can copy the function and paste it in the command line. You also need to set the savetext textid characteristic in the att.Then re-compile the FOSI and format the document. The error message should go away and the output should be as desired. If not, fillval the return value from the function into a usetext source instead of a savetext conrule so it is immediately output. You can debug from there.

The source command is documented in Help info, which also discusses startup files for production purposes.

Suzanne


kmccain
3-Newcomer
(To:kmccain)

First of all I want to thank everyone for their help and patience. I've just had a chance to fiddle with this again today and I found that if I put the acl script in the custom\editinit directory on my C: drive, it works when I call the function in the fosi. (after fixing the savetext rule!).


It does not work if it is in either the \custom\scripts or custom\init directories, although from what I read in the documentation, it looks like editor should search the init directory before editinit ??


I don't want to have to copy it to all the writers' PCs, so I created a documenttype.acl file in the dtd directory (which is in a network location) and put this function in it and it seems to work from there, although I cannot get it to work if I try to use an instance.acl file instead.. I have to admit, I'm not really sure what the difference is.. or which is better to use. But it's working! Thank you all so much! Now I'm hoping I can write some functions on my own to fix a few other things.

Announcements

Top Tags