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 an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Test for Child Element

SarahPrice
7-Bedrock

Test for Child Element

Is there a way to test for a specific child element and do a savetext based onif thatelement is there?Any help would be greatly appreciated.

Sarah
12 REPLIES 12

I use SYSTEM-FUNC pretty regularly in FOSI to call an ACL function and
grab the return as a savetext id.



The downside here is the oid of the current e-i-c isn't passed to the
function, so you'd have to get a little creative if there are several
identical parent/child pairs you are testing for.



<att>

<fillval attname="has_child" attloc="SYSTEM-FUNC" fillcat="savetext"&lt;br"/>
fillchar="conrule">

<charsubset>

<savetext textid="has_child.txt" placemnt="before"></charsubset>

</att>



Not sure how far this will get you down the road, but it might help.



I did have one FOSI/ACL combo that used a usetext rule=1 to write an
e-i-c specific info to an external file, then called a function from the
FOSI to read the external file and return the e-i-c specific info, but
it's hardly the most elegant solution.



You might browse the hook functions to see if there is something that
might help.



Hope this helped a little...



-Jason


Hi Sarah-



This following example from the online help may be useful. You should be
able to tweak the emptytestfunc() to do whatever test you need for child
element(s).



--Clay


A FOSI-only thing you could do is have a savetext on the child element,
and test for the child-element savetext in the parent element, and then
execute the parent-element savetext based on the existence of the
child-element savetext. You would need to make the child-element
savetext forward-referenced (status="1"). (<stringdecl<br/>textid="child-element-savetext" status="1">)


Not sure exactly what your goal is, but it's possible to initialize a text
variable (and perhaps reset it at some ancestor level) to " and then fill
it if the child element is found. Your output has to tolerate format + an
empty variable, though.

Paul is quite right that more information about your overall goal
would help us give you a better answer. There are several ways to
accomplish this, each with pros and cons. Which will work best will
depend on when during your formatting process you need to know if the
child is there or not, as well as things like performance issues and
scalability.

I'd probably try to do something like Ed and Paul suggest, sticking to
FOSI-only with savetexts. Whether you need to use a forward-reference
will depend, again, on what you need to do with the information.
Regarding the ACL solution that Jason suggests, the OID of the element
being processed most certain is passed to your function (see help 545
for details), so that should allow you to get whatever information you
need, though at a certain penalty of performance.

-Brandon 🙂

In Jason's reply, below, use a <specval...> and this function:

#--------------------------------------------------------------------
# get_first_childs_oid_name
#
# From a FOSI call, return the name of the first child element, or
# nothing if no child element.
#
#--------------------------------------------------------------------

function get_first_childs_oid_name(window, oid)
{
return oid_name(oid_child(oid));
}

So the <att> would be something like:
<att>

<specval attname="packagenamehere::get_first_childs_oid_name"&lt;br"/>attloc="SYSTEM-FUNC" attval="childnameyouneed"

>

<charsubset>

<savetext textid="has_child.txt" conrule="whatyouneedtosave"&lt;br"/>placemnt="before"></charsubset>

</att>


If I understood your need correctly.

The ACL is a copy of a function we already use. The <att> was composed
here on the fly. YMMV...

Hope that helps,
Steve Thompson
+1(316)977-0515
When the only tool you have is a hammer,
Everything looks like a hard disk...


I'm trying to generate a master TOC with page numbers generated from sections that may or may not have subsections:

My source document could look like this:

<description>
<title>TITLE</title>
<subsection label="A">
<title>SUBSECTION A TITLE</title>
</subsection>
<subsection label="B">
<title>SUBSECTION B TITLE</title>
</description>

Or like this:

<description>
<title>TITLE</title>
<para0 &quot;a&quot;=">
<title>SUBSECTION TITLE</title>
</para0>
</description>

If the section has subsections then the page numbering would be 1A-1, 1A-2, etc.

If not the page numbering would be 1-1, 1-2, etc.

I have all page numbering correct in the Main TOC except where it reads the Description Title. I'm getting 1-1 instead of 1A-1.

I tried Ed's suggestion but I must be doing something wrong.

Thanks for all your help and all the responses.

Sarah


Hi, Sarah...

Yes, this makes things much clearer. The TOC entry for the
Description Title is being generated before the FOSI has seen the
subsection element and altered the page numbering accordingly.

I'd suggest trying to generate the TOC entry for the description title
in the first subsection or para0, at which point you'll know for sure
the correct page numbering style. You should be able to target this
case by copying the e-i-c for subsection and adding an occur="first",
then moving the description title TOC code there. You'll then need to
do the same for para0.

Alternatively, you could try to do this without copying the e-i-c
(always good to avoid duplicating code, though FOSI doesn't often make
it easy). You might try creating an att rule based on the value of a
counter or text variable that is modified with each subsection, or
something along those lines. This isn't as clear-cut as the "occur"
solution, though.

-Brandon 🙂

On Tue, Sep 15, 2009 at 12:50 PM, Copley, Sarah
CTR<sarah.r.copley@uscg.mil> wrote:
> I'm trying to generate a master TOC with page numbers generated from sections that may or may not have subsections:
>
> My source document could look like this:
>
> <description>
> <title>TITLE</title>
> <subsection label="A">
> <title>SUBSECTION A TITLE</title>
> </subsection>
> <subsection label="B">
> <title>SUBSECTION B TITLE</title>
> </description>
>
> Or like this:
>
> <description>
> <title>TITLE</title>
> <para0 &quot;a&quot;=">
> <title>SUBSECTION TITLE</title>
> </para0>
> </description>
>
> If the section has subsections then the page numbering would be 1A-1, 1A-2, etc.
>
> If not the page numbering would be 1-1, 1-2, etc.
>
> I have all page numbering correct in the Main TOC except where it reads the Description Title. I'm getting 1-1 instead of 1A-1.
>
> I tried Ed's suggestion but I must be doing something wrong.
>
> Thanks for all your help and all the responses.
>
> Sarah
>

Oh, I forgot - Using this scenario, you would also need to set the text
variable to null/blank at the parent element
(child-element-savetext="\\") in case the document contains other parent
elements without the child element.


I did try that and it was successful however when I clicked on the page number in the Main TOC it took me to the Para0 title instead of the description title.

Sarah,

You might try saving the title of the description into another text id
(which also has hotlink="1") in the e-i-c for the description title,
then use that to build the toc entry in the subsection or para0 e-i-c,
as you are doing now. I think this will fix the misdirected link
issue.

-Brandon 🙂

On Tue, Sep 15, 2009 at 2:29 PM, Copley, Sarah
CTR<sarah.r.copley@uscg.mil> wrote:
> I did try that and it was successful however when I clicked on the page number in the Main TOC it took me to the Para0 title instead of the description title.
>

You are absolutely right. That is what we did and it worked perfectly. Thanks for all your help! Problem has been solved.

Sarah
Top Tags