Name Variants

The <baseNameString> element contains only PCDATA, but you will recall that non-string resources such as graphics can be used to label topics. This facility is provided by the <variantName> construct. A single base name may have any number of variant names associated with it. The structure of a <variantName> element is very similar to that of an <occurrence> - it may contain either an inline string resource or a reference to an external resource.

Unlike occurrences, variant names are not typed; however, they do have a mechanism for indicating the kind of variant that they are. A variant may have any number of parameters which indicate the nature of the variant. As with types, each parameter is defined by a topic, and the topic map paradigm allows an author to use any topic he or she likes as a parameter. Sample 4 shows our company topic with a variant name which is the normalised sort string for the topic. This sort of variant name might be used by an application to order a list of companies (although the base name string itself would be the one used for display purposes).

<topicMap>
  <topic id="sort-string"/>
  <topic id="xyzzy">
    <baseName>
       <baseNameString>Redmond Computers Inc.</baseNameString>
       <variant>
         <parameters>
           <topicRef xlink:href="#sort-string"/>
         </parameters>
         <resourceData>redmond computers incorporated</resourceData>
       </variant>
    </baseName>
  </topic>
</topicMap>
        

Sample 4 - Variant names

Variants can also be nested within each other. A variant nested inside another variant inherits all of the parameters of its parent. So if we have, for example, icons of different sizes, we can use nesting to group them all together. This is shown in Sample 5 - the two variants with <resourceRef> elements pointing to icons are identified with a single parameter indicating their size. They inherit the parameter indicating that they are icons from the containing <variant> element. It should be noted that the topics with id attribute values of "icon", "_16x16" and "_32x32" are the minimal mark-up possible for a topic. This is not a recommended approach to topic creation, but is used here to save space.

<topicMap>
  <topic id="icon"/>
  <topic id="_16x16"/>
  <topic id="_32x32"/>
  <topic id="xyzzy">
    <baseName>
       <baseNameString>Redmond Computers Inc.</baseNameString>
       <variant>
         <parameters>
           <topicRef xlink:href="#icon"/>
         </parameters>
		<variant>
		  <parameters>
             <topicRef xlink:href="#_16x16"/>
           </parameters>
           <variantName>
             <resourceRef xlink:href="http://www.myserver.com/icons/16x16/redmond.png"/>
           </variantName>
         </variant>
         <variant>
		  <parameters>
             <topicRef xlink:href="#_32x32"/>
           </parameters>
           <variantName>
             <resourceRef xlink:href="http://www.myserver.com/icons/32x32/redmond.png"/>
           </variantName>
         </variant>
       </variant>
    </baseName>
  </topic>
</topicMap>
        

Sample 5 - Nested variants

Up: Topic Map Basics
Previous: Types Next: Scope