Stylesheet Development with PTC ALD > Adding PTC APP Code to Stylesheet Source > Samples > Testing > Test Attribute Values and Apply Formatting Properties > Set Multiple Properties
  
Set Multiple Properties
The sample listed here describes how to set text height, text color, and capitalization mode for a piece of inline text in a single command, based on the current value of one of its attributes.
Refer to the emphasis in para[3] in sect1[3] context in the stylesheet Arbortext-path/samples/ALD/Testing/Attributes/applyAttributes.style. The context includes an PTC APP source code edit. The relevant code is shown below:
var propList = arguments[0].attributes.role.split(", ");

//Text height
style.height = propList[0];
//Text colour
style.color = propList[1];
//Capitalisation
switch (propList[2]) {
case "caps":
style.capsMode = fStyle.CAPS_UPPER;
break;
case "small":
style.capsMode = fStyle.CAPS_SMALL;
break;
case "normal":
style.capsMode = fStyle.CAPS_NORMAL;
break;
}
The individual sections are described in more detail below.
var propList = arguments[0].attributes.role.split(", ");
Create the variable propList. Specify that the content of the variable will be an array of values extracted from the role attribute on the current element. Call a split method to split a string into an array of substrings. Clarify with (", ") that a comma and a space separates the individual values of role in the array.
style.height = propList[0];
Set the text height for the current element.
The first part of the phrase style.height specifies that you want to provide a value for the height property for the style of the context, which is based on an fStyle object. The second half = propList[0] confirms that the first value [0] in the array stored in the propList variable will provide the value for the height property.
style.color = propList[1];
Set the text color for the current element.
The first part of the phrase style.color specifies that you want to provide a value for the color property for the style of the context, which is based on an fStyle object. The second half = propList[1] confirms that the second value [1] in the array stored in the propList variable will provide the value for the color property.
switch (propList[2]) {
case "caps":
style.capsMode = fStyle.CAPS_UPPER;
break;
case "small":
style.capsMode = fStyle.CAPS_SMALL;
break;
case "normal":
style.capsMode = fStyle.CAPS_NORMAL;
break;
}
Set the capitalization mode for the current element.
Use a switch statement to create a list of possible options (cases) for processing the third value [2] in the array stored in the propList variable.
The switch statement works in three stages:
1. The third value [2] in the variable propList is evaluated
2. The value of propList[2] compared with the values for each case entry
3. If the value of propList[2] matches a case entry in the switch statement, the block of code associated with that case is executed.
An entry of break prevents one case from running into the next
So if the inline text appears as <emphasis role=”30pt, red, caps”>Inline text</emphasis> in the document source, the case case "caps" will match. The code phrase style.capsMode = fStyle.CAPS_UPPER; will be executed. The first part of the phrase style.capsMode specifies that you want to provide a value for the capsMode property for the style of the context, which is based on an fStyle object. The second half = fStyle.CAPS_UPPER; confirms that the constant CAPS_UPPER for the fStyle object should be called. This constant is declared as part of the StyleCapsMode group for fStyle, and displays text in upper case.