Skip to main content
1-Visitor
September 24, 2013
Question

savetext value with leading zeros and FOSI

  • September 24, 2013
  • 19 replies
  • 2833 views

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

    1-Visitor
    September 24, 2013
    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
    >
    1-Visitor
    September 24, 2013
    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!"




    1-Visitor
    September 24, 2013
    Paul,

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

    Suzanne


    1-Visitor
    September 24, 2013
    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


    kmccain1-VisitorAuthor
    1-Visitor
    September 25, 2013

    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

    1-Visitor
    September 25, 2013
    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




    1-Visitor
    September 25, 2013
    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
    1-Visitor
    September 25, 2013
    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
    kmccain1-VisitorAuthor
    1-Visitor
    September 26, 2013

    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.

    1-Visitor
    September 27, 2013
    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