String transformation rules are used to transform an input character string to a user-friendly output character string. In NXT, transformations are used for the following:
There are two types of transformations that you can create:
Find-replace transformations use find
and replace
attributes that are stated in the XIL file. A Find-replace transformation replaces all entries corresponding to the find
attribute with entries of the replace
attribute. You can compose transformation rules using the syntax of a Find-replace transformation. Consider the following <rule>
node:
The transformation in the previous example finds all underscores in the source string and replaces them with spaces. When this <rule>
node is added to the XIL file, the output for the string day_of_week
is transformed to day of week
.
Use the regular expressions that follow ECMAScript syntax for the find
attribute and the substitution syntax for the replace
attribute. For example, to convert the string the number is 1234 or 5678
to the string the number is code(1234) or code(5678)
, use the following <rule>
node:
A digit between percent signs ( % ) is the match number in the regular expression.
For case shift, use following converters between percent signs ( % ):
The following example converts the string this is the test
to the string this is the TEST
:
The following example converts the first letter of each word to uppercase:
If the match
and replace
attributes are specified in the <rule>
node, and the find
attribute is not specified, the match-replace transformation is performed. If the source string completely matches the category that is specified in the match
attribute, this string is replaced by the category of the replace
attribute. Use regular expressions that follow ECMAScript syntax for the match
attribute and the substitution syntax for the replace
attribute. The following example converts the string 4
to the string Less than 5 (4)
:
Note: Find-replace transformations replace all occurrences of a specified attribute in facets and facet categories. For example, the text
facet changes to test
, if you apply the following rule to this facet: <rule find="x" replace="s"/>
. But with the match-replace transformation the text
facet remains unchanged, because you search for a facet or a facet category that fully matches the specified attribute.
The string transformation engine recursively passes through all of the <rule>
nodes.
The source string is passed only to the first <rule>
node. The other <rule>
nodes receive the results from the previous node.
If a node contains child nodes, the transformation of the parent node is performed fist, and then the results are passed to the child nodes.
The following rules are used in the string transformation algorithm:
match
attribute is specified and the string does not match this attribute,
then all of the other attributes are ignored and the node, and all of its child nodes, is ignored.
match
attribute is specified, the <rule>
node is used as a filter.
If the match occurs, the processing is passed to the child nodes.
In this case, you can sort the source strings by types (for example, dates, locations, or material types) and increase performance by excluding most of the nodes when the string is processed.
find
and replace
attributes are specified, the find-replace transformation is performed.
match
and replace
attributes are specified, the match-replace transformation is performed.
In this case, the match
attribute can be used both as a filter and a source of substitution for the transformation.
stop
attribute is specified, this id the last transformation.
The recursive algorithm finishes. This also helps to increase performance.
You can use facet rule tester to validate transformation rules for strings in the XIL file. Since the 4.8 version of NXT, the facet rule tester is included in the NXT Builder and is available in c:\Program Files\Rocket\NXT 4\Builder\bin\
directory for 32-bit Windows version, and in c:\Program Files (x86)\Rocket\NXT 4\Builder\bin\
directory for 64-bit Windows version.
To validate the transformation rules with the facet rule tester, complete the following steps:
Note: Before validation, check that the XIL file has the <facet-name-rules>
section.
The facet rule tester tracks changes in the XIL file. You can save changes in the XIL file and immediately see the results of transformation in the Result column. For additional convenience, you can select Always on top and Opacity settings from View menu.
You can also test the rules in Content Network Manager in Edit title rules dialog.
Copyright © 2006-2023, Rocket Software, Inc. All rights reserved.