B.4 Bind Values

Binding of values is one of the core functions of the dynamic SVG binder. You can create a bind command that sets the attribute of its parent element, or sets the text value. The bind command does two things: It specifies how to generate the value to be set, and also specifies where that value is to be placed. Binds are probably the single most used command, so the default behavior of any element in the bind namespace is to set an attribute of that name:

<bind:anything value-expressions.. />

You can also specify the attribute you want to set by including it on the general form of the command:

<bind:value attr="attrname" value-expressions... />

It’s common to set the text content of the parent element, rather than set an attribute. A bind:value without an attribute does this:

<bind:value value-expressions... />

Value-expressions generate the strings that are placed as text content or as attributes. You can gather properties from bound elements, use special property forms for convenience, execute velocity expressions, and execute xpath expressions.

B.4.1 Bind Value Attributes

Bind values attributes:

  • attr: Names the attribute on the parent element that is set by this binding command.

    When not present and no special form is being used, the text content of the parent element is set.

  • bulkattrs: Names a list of comma separated element properties to request and cache in a single request. Requires the use of NOC script to display the values.

    Must use cachingelement instead of element to request the attriubes at the NOC script level. This element provides the cached attributes specified by the bulkattrs attribute.

    For example, see Section B.4.2, Using NOC Script in Bind:Value Tag. For information about available script objects, see Section B.8, Script Objects

  • property|prop|p: Specifies a property to retrieve on the bound element, or specifies the name of a specially handled property.:

    • childcount: The number of NAM children of the element.

    • orgchildcount: The number of ORG (contributing) children of the element.

    • condition: Translates the condition of the element into an SVG color.

    • conditionhighlight: Translates the condition of the element into a somewhat lighter SVG color.

    • conditiontext: Name of the condition.

    • conditionbackground: Background color, usually the same as condition.

    • conditionforeground: Color for text foreground — make this the color of conditiontext if the text is written against a fill of condition.

    • conditiongradient: Translates the condition of the element into a nice horizontal gradient reference. When specifying conditiongradient you can also specify the prefix attribute. The bind engine appends the integer value of the ElementCondition to the prefix you specify:

      <bind:value attr="fill" property="conditiongradient" 

      If the element’s condition is critical, change the fill property to:

    • DName: Retrieves the DName of the element.

    • name: Retrieves the name of the element.

    • image: Creates an in‑line reference to the element’s large icon.

    • smallimage: Creates an in‑line reference to the element’s small icon.

    • scope: Instructs the bind engine to perform a scoped lookup for the property name. This is normally used only with the bind:properties template expression, where the cloned elements are generated with property attributes set on them.

  • value|val|v: Contains a NOC Script expression that is evaluated.

    The result is a string that is set to the named attribute.

  • xpath|xp|x: Specifies an xpath expression.

    The xpath expression is executed with the binding element as its context. The resulting nodes will have their text contents extracted, appended together, and set as the value of the attribute.

  • format: Supplies additional formatting for some kinds of objects.

    For java.util.Date, this can be set to time, date, date/time, or to any date/time formatting string that is acceptable to the java.text.SimpleDateFormat class. For other, nondate objects, the format string is passed to Java’s String.format method, allowing arbitrary formatting. For the format string syntax and possibilities, see the Java documentation.

  • when: If specified, the result of the value-expressions must match one of the entries in the when clause, which is a comma-separated list.

    If a match is not found, the default value (defined next) is used.

  • default, else: Defines a value to be use if the expression results in an empty string, or if the when clause fails.

  • set: Used in conjunction with when to provide a simple “if” capability.

    If the when condition matches, the value of the set attribute is returned. If the condition does not match, the default attribute’s value is used.

B.4.2 Using NOC Script in Bind:Value Tag

Using NOC script inside the Bind:Value tag, you can perform a single request to display the values of element multiple properties in the Layout view.

As described above, this mechanism makes a single request for needed element properties for a given drawing instead of making several individual requests. This can be especially beneficial in cases when a node style displays multiple property values; where instead of multiple requests, all values for all elements are returned by a single request.

For non-script bindings in the Layout view, these attributes are auto-detected by the engine. But, when using NOC script, the user must specify the element properties to be bulk requested in the bulkattrs attribute, then use cachingelement to retrieve the values to a variable which is then used to display them.

In the following example, NOC script is used to display 5 custom attributes on an element:

<text x="14" font-size="14pt" y="131" fill="#000000" text-anchor="middle" filter="none" opacity="1" stroke="none"> <bind:value bulkattrs="PropertyName1,PropertyName2,PropertyName3,PropertyName4, PropertyName5"><![CDATA[ var val1 = cachingelement["PropertyName1"]; var val2 = cachingelement["PropertyName2"]; var val3 = cachingelement["PropertyName3"]; var val4 = cachingelement["PropertyName4"]; var val5 = cachingelement["PropertyName5"]; val1+":"+val2+":"+val3+":"+val4+":"+val5 ]]>

When the code is rendered, the output is something like the following:


For information about available script objects, see Section B.8, Script Objects