Skip to main content
Participating Frequently
June 2, 2025
Answered

Display of all strings values in $attribute

  • June 2, 2025
  • 2 replies
  • 1033 views

Hi community,

I have this in me EDD:

 

Prefix rules
In all contexts.
Prefix: Tails: <$attribute[Tails:ItemL3]>

 

the "Tails" attribute is a strings attribute, with multiple values in some cases, however I only get the first value displayed. How can I get all values displayed?

 

TNX

Correct answer frameexpert

Here is a 2-minute video that illustrates a basic scripting solution:

https://youtu.be/jXNOxYYZWhE

 

Here is the code I am using in the video:

main ();

function main () {
    
    var doc, element;
    
    doc = app.ActiveDoc;
    // Make sure there is an active document.
    if (doc.ObjectValid () === 1) {
        element = doc.MainFlowInDoc.HighestLevelElement;
        // Make sure the document is structured.
        if (element.ObjectValid () === 1) {
            processElement (doc);
        }
    }
}

function processElement (doc) {
    
    var element, values;
    
    // Get the currently selected element.
    element = doc.ElementSelection.beg.child;
    if (element.ObjectValid () === 1) {
        // Call a function to get a comma-separated list of
        // Tails attribute values.
        values = getAttributeValues (element, "Tails");
        if (values) {
            // Apply the list to the "display" attribute
            // used in the Prefix rule.
            setAttributeValue (element, "Tails_display", values);
        }
    }    
}

function getAttributeValues (element, name) {
    
    var attrList = element.Attributes, i = 0;
    
    var attrList, count, i;
    
    attrList = element.Attributes;
    count = attrList.length;
    
    for (i = 0; i < count; i += 1) {
        if (attrList[i].name === name) {
            if (attrList[i].values.length > 0) {
        		return (Array.prototype.join.call (attrList[i].values, ", "));
            }
        }
    }
}

function setAttributeValue (element, name, value) {
    
    // Sets the value of an attribute on the element.
    
    var attrList = element.Attributes, i = 0;
    for (i = 0; i < attrList.length; i += 1) {
        if (attrList[i].name === name) {
            attrList[i].values[0] = value;
            element.Attributes  = attrList;
            return;
        }
    }
}

2 replies

frameexpert
Community Expert
Community Expert
June 3, 2025

Because of the limitation that you discovered and Lynn confirmed, I would considering adding a second attribute; for example, Tails_display. Then you could use ExtendScript to automatically populate the Tails_display attribute with a comma-separated list of values of the Tails attribute for each element. You could refer to this attribute in your EDD.

 

A script can be triggered when an attribute value is set, so it could be mostly transparent to the user. Or, if your XML is being imported into FrameMaker, you could use XSLT like Lynn suggested. Please let me know if you want to explore a scripting or XSLT solution.

Shai GillAuthor
Participating Frequently
June 3, 2025

Thanks!

I would definitely want to explore both, but being the newbie I am I would appreciate the help!

 

Shai

frameexpert
Community Expert
frameexpertCommunity ExpertCorrect answer
Community Expert
June 3, 2025

Here is a 2-minute video that illustrates a basic scripting solution:

https://youtu.be/jXNOxYYZWhE

 

Here is the code I am using in the video:

main ();

function main () {
    
    var doc, element;
    
    doc = app.ActiveDoc;
    // Make sure there is an active document.
    if (doc.ObjectValid () === 1) {
        element = doc.MainFlowInDoc.HighestLevelElement;
        // Make sure the document is structured.
        if (element.ObjectValid () === 1) {
            processElement (doc);
        }
    }
}

function processElement (doc) {
    
    var element, values;
    
    // Get the currently selected element.
    element = doc.ElementSelection.beg.child;
    if (element.ObjectValid () === 1) {
        // Call a function to get a comma-separated list of
        // Tails attribute values.
        values = getAttributeValues (element, "Tails");
        if (values) {
            // Apply the list to the "display" attribute
            // used in the Prefix rule.
            setAttributeValue (element, "Tails_display", values);
        }
    }    
}

function getAttributeValues (element, name) {
    
    var attrList = element.Attributes, i = 0;
    
    var attrList, count, i;
    
    attrList = element.Attributes;
    count = attrList.length;
    
    for (i = 0; i < count; i += 1) {
        if (attrList[i].name === name) {
            if (attrList[i].values.length > 0) {
        		return (Array.prototype.join.call (attrList[i].values, ", "));
            }
        }
    }
}

function setAttributeValue (element, name, value) {
    
    // Sets the value of an attribute on the element.
    
    var attrList = element.Attributes, i = 0;
    for (i = 0; i < attrList.length; i += 1) {
        if (attrList[i].name === name) {
            attrList[i].values[0] = value;
            element.Attributes  = attrList;
            return;
        }
    }
}
Matt-Tech Comm Tools
Community Expert
Community Expert
June 2, 2025

Please share the attlist

 

-Matt Sullivan, FrameMaker Course Creator, Author, Trainer, Consultant
Shai GillAuthor
Participating Frequently
June 2, 2025

 

Element (Container): ItemL3
General rule: ~-Assembly Data?, Tails?, (((ItemRepeat, ItemRepeat)?, (ItemNumber, ItemHeading, Asterisks?)?, Note*) | (DispatchCondition | (DispatchConditionWithOption, DispatchConditionWithOption+))), ItemL4*
Attribute list
Name: FDaOptions Strings Optional
Name: Tails Strings Optional

 

 

Matt-Tech Comm Tools
Community Expert
Community Expert
June 2, 2025

It's not easy to follow, as you have both an element and an attribute named TAILS. 

 

As written, it looks like you are asking to display the Tails attribute value(s) on an ancestor element named ItemL3.

Does it work if you rewrite it as 

Prefix: Tails: <$attribute[Tails]>

 

For more detail, see the last example on p123 of FrameMaker - Structured EDD Development Workbook

 

-Matt Sullivan, FrameMaker Course Creator, Author, Trainer, Consultant