Tag Templates
Context: HL Kit … Basic Concepts and Terminology … Tags and Tag Expressions
Overview
All things are assigned an assortment of tags that reflect the various characteristics of those things. Tags can be utilized by the data file author to identify things that must adhere to rules or should be subject to specific types of processing. You can assign tags to picks and containers dynamically during evaluation processing to change their nature and behavior. Tags can even be utilized by the end-user to filter things in arbitrary combinations. So now the question is how to identify the things that have the specific tags you are seeking. The basic mechanism is called a tag template.
Basic Usage and Syntax
Tag templates represent a kind of "query" that compares an object against a specific tag, or possibly a group of similar tags using a wildcard. Either the object contains one or more tags that match the template or not. In general, a tag template returns the number of tags within the object that match the template. How that value is used depends on the context in which it is used.
Tag templates identify a specific tag group and a comparison string that can match zero or more tags within that group. The syntax for a tag template is "group.compare", where "group" is the unique id of a specific tag group and "compare" is a comparison string to match against individual tags within the group. The two values are always separated by a period. The comparison string always compares against the unique id assigned to tags.
Note that tag templates always utilize the unique ids of the tag and the group. This makes tag usage completely independent of that actual names used for tags and/or tag groups.
For example, a tag template to identify all objects of the color red would be defined as "color.red". The unique id of the tag group is given first ("color"), followed by the unique id of the tag itself ("red").
Wildcards
The simplest tag template specifies an explicit tag (e.g. "color.red"). However, the '?' character can be placed at the end of a comparison string to denote a wildcard. When a wildcard is used, the template will match all tags whose unique id matches the comparison string up to the '?'. For example, the tag template "color.bl?" would match both of the tags "black" and "blue" for the group "color", but it would not match the tag "red". The wildcard character can only be specified at the end of a comparison string. Any characters occurring after the '?' will trigger a compiler error as invalid syntax.
Some examples of tag templates are provided below to illustrate how they can be used.
color.red Matches only the tag "red" within the group "color". color.bl? Matches any tag that starts with the letters "bl" within the group "color". For example, this template would match tags for the colors "black" and "blue", but it would not match "red". It would also match the tag "bl". color.? Matches any tag within the group "color", provided the object has at least one "color" tag. If the object does not possess any tags from the group "color", the template will resolve to "false".
Important Considerations
Keep the following issues in mind when dealing with tag templates.
- All tag ids are case-specific, and so are tag templates. Be careful to specify the correct case for all templates.
- The comparison string utilizes the unique id for tags. If there are a number of related tags with which you want to be able to utilize wildcards, consider assigning them unique ids that make this possible. For example, if you have a "bigorc" and a "smallorc" tag, you could rename them as "orcbig" and "orcsmall". Using wildcards, you could reference both tags via the comparison string "orc?". This naming technique allows you to reference the two "orc" tags either independently or collectively, as the situation dictates.
- The tag template "group.?" can be extremely useful in various situations. Table selection and validation rules are often specific to objects from a given category. By creating a tag group for the desired category and using the "group.?" syntax, you can instantly identify all objects from a particular category of interest.