• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

replace the text of an element with tag <bold>

New Here ,
Nov 06, 2015 Nov 06, 2015

Copy link to clipboard

Copied

Dear all,

I want to change the complete text of an element with a certain tag, say "<bold>".

I can get the tag name via elem.ElementDef.Name. But how do I get the text()-node of the Element.

Is there something like the xslt text()-node functionality? Some other ideas?

Thanks in advance

WA

TOPICS
Scripting

Views

778

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Nov 06, 2015 Nov 06, 2015

function replaceElementText(doc, elem, newText)

{

    //Define a new element range and set it up

    //to represent the contents of the element.

    var er = new ElementRange();

    er.beg.parent = er.end.parent = elem;

    er.beg.offset = 0;

           

    if(ov(elem.FirstChildElement))

    {

        er.beg.child = elem.FirstChildElement;

        er.end.offset = 0;

    }

    else er.end.offset = Constants.FV_OBJ_END_OFFSET;   

   

    //Set the element range in the document and

    //execu

...

Votes

Translate

Translate
Mentor ,
Nov 06, 2015 Nov 06, 2015

Copy link to clipboard

Copied

Hi WA,

Good question. There is no concept of a single text node within a FrameMaker element like there is for other DOM tools. But even if there was, there still would be no direct method to set the text. In FrameMaker, you have to deal with element ranges and text selection tools to complete this kind of operation.

Here is a function that replaces the text of the provided element. Hope this helps.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 06, 2015 Nov 06, 2015

Copy link to clipboard

Copied

function replaceElementText(doc, elem, newText)

{

    //Define a new element range and set it up

    //to represent the contents of the element.

    var er = new ElementRange();

    er.beg.parent = er.end.parent = elem;

    er.beg.offset = 0;

           

    if(ov(elem.FirstChildElement))

    {

        er.beg.child = elem.FirstChildElement;

        er.end.offset = 0;

    }

    else er.end.offset = Constants.FV_OBJ_END_OFFSET;   

   

    //Set the element range in the document and

    //execute Clear() to delete the current element contents.

    doc.ElementSelection = er;   

    doc.Clear(0);

   

    //The insertion point will now be at the beginning of

    //the empty element. Execute AddText() to insert the

    //new text.

    doc.AddText(doc.TextSelection.beg, newText);  

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Nov 06, 2015 Nov 06, 2015

Copy link to clipboard

Copied

WA,

I just noticed one thing in my code that won't work for you, that ov() call. That is a personal shortcut to determine the validity of an object. Here is the code:

function ov(obj)

{

    if(obj == null) return false;

    else return obj.ObjectValid();

}

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 10, 2021 Aug 10, 2021

Copy link to clipboard

Copied

How to do this scripting in FM, could you please help me?....I am not a coding person...We have to replace the bold format applied in the text with the bold tag, we have 3000+ pages, so automation will save the manual work. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

If you are "not a coding person," you will either need to take some time to learn how, or pay someone else to do it. It would not be possible to teach you how with a simple forum reply.

 

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

I can take the support from the coding person in my team....we just need to know the concept

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

Like how to use the script in framemaker 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

Unfortunately, your question is too broad. We can't teach you how to write scripts for FM. We can answer specific questions that you may have along the way but we can't start you from the beginning. The coding person on your team needs to figure it out or you just need to hire a contractor. There are high-quality people available who do this kind of work.

 

Russ

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 11, 2021 Aug 11, 2021

Copy link to clipboard

Copied

As Russ said, some of us here do this for a living. If you are interested in an estimate for a script like this, please contact me off list. rick at frameexpert dot com

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

Hi,

I would like to know about the estimate and ETA for the script. 

Please let me know the contact details to discuss on the same.

 

Thanks,

Priyanka

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 13, 2021 Sep 13, 2021

Copy link to clipboard

Copied

LATEST

@Priyanka5FC3 - contact Rick by Private Message or by e-mailing him using that address he gave.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines