String information

The info attribute returns information about a string and assigns that information to a user variable.

<set var="UV" string="STR" info="TYPE" />

where TYPE is one of:

  • LENGTH — if present, TopLeaf counts the number of text characters in the string assignment, then assigns the calculated value to the target variable. For the purposes of counting, entities within the string are regarded as single characters. The length of an empty string is not defined.

    The following example shows how to apply an optional compression to content that has a declared length that exceeds 5 characters:

    <set var="MaxLength" value="5" />
    <set var="DescMeas"  string="{content}" info="length" />
    <switch>
      <case var="Meas" target="{MaxLength}" test="not-less">
        <Compress type="desc">{content}</Compress>
     </case>
     <case>{content}</case>
    </switch>
    
  • MEASURE — if present, TopLeaf estimates a minimum horizontal measure for the string assignment, then assigns the calculated value to the target variable. The assigned value is calculated using the current font specification, and is always declared as a decipoint value. The horizontal measure of an empty string is not defined.

    Note that TopLeaf can only calculate the measure for variables that contain:

    1. character data;

    2. references to numeric character entities;

    3. references to the named character entities &amp;&lt;, and &gt;

    or where the replacement text generated for an entity reference contains any of the above.

    The following example shows how to apply an optional compression to content that has a measured width that exceeds 35mm:

    <set var="MaxMeas"  value="35mm" />
    <set var="DescMeas" string="{content}" info="measure" />
    <switch>
      <case var="Meas" target="{MaxMeas}" test="not-less">
        <Compress type="desc">{content}</Compress>
     </case>
     <case>{content}</case>
    </switch>
    
  • WORDCOUNT — if present, TopLeaf counts the number of white space separated words within the string assignment, then assigns the calculated value to the target variable.

    The following example shows how to apply an optional compression to content that contains a single word:

    <set var="Words" string="{content}" info="wordcount" />
    <switch>
      <case var="Words" target="1" >
        <Compress type="desc">{content}</Compress>
     </case>
     <case>{content}</case>
    </switch>