Community Tip - If community subscription notifications are filling up your inbox you can set up a daily digest and get all your notifications in a single email. X
Hi,
We're trying to eliminate an element used throughout our document in Arbortext, but retain the text it's wrapped in.
The issue is nearly resolved following the solution provided in this topic:
Solved: Re: Remove <P> element from a table - PTC Community
This solution works for our issue, but only for tags in tables. Our target tag could have any parent. I have tried modifying this line...
if (oid_name(oid_parent($arr[$i])) == "entry")
...replacing "entry", but had little luck.
Here's the script as it currently exists:
function remove_text_tags()
{
local oid = oid_first_tag()
local cnt
local i = 1
cnt = oid_find_children(oid, $arr, "text")
for ($i=1; $i<=$cnt; $i+=1)
{
if (oid_name(oid_parent($arr[$i])) == "entry")
{
goto_oid($arr[$i],-1)
dt
}
}
}
Thanks for any help!
Jeff
Solved! Go to Solution.
If you don't care what the parent is, you just want to remove them all, then why not simply remove the parent test altogether?
function remove_text_tags() {
local oid = oid_first_tag()
local cnt
local i = 1
cnt = oid_find_children(oid, $arr, "text")
for ($i=1; $i<=$cnt; $i+=1) {
goto_oid($arr[$i],-1)
dt
}
}
What element is your text currently in, and what element are you trying to remove.
We use this solution when you copy and paste into a table and each piece of text was wrapped in a <P> element in a entry element. This removed the <p> element and left the text in the entry element.
Bryon
Hi Bryon,
The element we are trying to remove (but retain its text) is throughout our document. When the text element happens to be in a table, this script works perfectly. However, the text element could be present in any element of our document where text could be entered (i.e., title, cmd, p, ph, etc.) as shown below.
After running the script, we want the text to appear as follows.
I can simply add each possible parent (for example, if (oid_name(oid_parent($arr[$i])) == "cmd" || "p" || "ph" || "entry" || "i" || "li" ...and so on...), but figured there was a more efficient way of going about this.
Regards,
Jeff
If you don't care what the parent is, you just want to remove them all, then why not simply remove the parent test altogether?
function remove_text_tags() {
local oid = oid_first_tag()
local cnt
local i = 1
cnt = oid_find_children(oid, $arr, "text")
for ($i=1; $i<=$cnt; $i+=1) {
goto_oid($arr[$i],-1)
dt
}
}
Hi Clay,
I know I had removed the parent test originally but received some kind of error. This time it worked! I was working on various scripting solutions at the time, so I must have gotten my wires crossed and just need to step away from it for a bit. Thank you so much!
Regards,
Jeff
Hi Jeff,
It looks like you are trying to flatten out the change tracking elements in your document. What you need is a "tree walker" function. That is so common it is even covered in the PTC documentation: https://support.ptc.com/help/arbortext/r8.2.1.0/en/#page/Program%2Fprogrammer_ref%2Ftraversing_and_printing_a_document_structure.html
EDIT: Oh it looks like the getElementsByTagName() might even do the tree walk for you? https://support.ptc.com/help/arbortext/r8.2.1.0/en/#page/Program%2Fprogrammer_ref%2Fusing_getelementsbytagname.html
I believe that searching through all the .acl files that ship with the product will produce more examples of this type of algorithm too. Anywhere it is doing oid_find_children() is probably a good candidate, and especially where that function calls itself recursively.
Basically, the recursive tree walker algorithm for your usage is something like this:
1. Set document root node as context node
2. List the child nodes for the context node
3. For each child node, set it as the context node and go to step #2 (this is the recursive part), unless...
4. ... if only child text nodes remain then check the context node, is it the <text> element with status="changed"?
4.a. if the node is one to remove, then delete it
4.b. if the node doesn't match then leave it be and keep going
I don't have a working copy of Arbortext right now so I can't check further but hopefully that keeps you moving. The problem with the code you pasted is it is not recursive. It only works on one level of child nodes.
Hi Gareth,
Sorry for the late reply. I don't get to work with Arbortext as much as I'd like (or need) to as other projects developing content keep coming up.
This sounds like really useful information that I hope to research as I learn more about scripting. Thank you for providing all of that information!
Regards,
Jeff