Key-Value Lookup Example (Tridion R5.3)

The following is adapted from a post of mine on the Tridion World Forum (an account required which is available to Tridion clients). Key-value "lookup tables" can be stored in xml files to manage Tridion-related information such as identifiers (tcm ids) or  other not-so-friendly key names and their corresponding friendly values. For example, rather than hard-coding unique Tridion identifiers for each environment, we can output a text-based configuration file. This simple example highlights re-use, separation of layers, and ease of content (re)creation.

1) Ordered Pair - embeddable schema Consisting of two items:
  • key (text)
  • value (text)
Description can be first and second item, with mention of "key" and a friendly name. This could even be localized to match the needs of a given publication and/or (end-user) language.

2) List of Ordered Pairs - schema Consists of one item: ordered pair (the embedded schema above, allowing multiple values) (also give this a useful namespace such as:

3) Key Value XML Output - Component Template (XSLT)
(match the namespace above, the names space will differ in different versions of Tridion)

<xsl:stylesheet version="1.0"
 exclude-result-prefixes="xsl tcm xlink tcmse listorderedpair">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
<xsl:template match="/">
    <xsl:apply-templates select="/tcm:Component/tcm:Data/tcm:Content/*" />
<xsl:template match="*">
  <xsl:for-each select="//listorderedpair:orderedpair">
      <xsl:attribute name="key">
       <xsl:value-of select="listorderedpair:key" />
      <xsl:value-of select="listorderedpair:value" />

4) Ouput Generic XML - Page Template (VBScript, but any templating language can work)

[% 'this outputs a physical xml file
'component and corresponding component template that outputs actual xml via XSLT is required
 for each comp in page.componentpresentations
   writeout comp.content


To create the lookup XML file after setting up the embeddable schema, regular schema, and templates, first create a component based on List of Ordered Pairs. Then create the page, add the component (+ template = component presentation), and publish. The resulting file will look like:
 <value key="1">First Value</value>
 <value key="2">Second Value</value>
This example can relate  friendly names to their programatic equivalents. This can work in other scenarios and can serve as a general content-to-physical-xml file example.
If you've ever needed to make a quick and robust interface for this type of configuration data (or any content), a WCMS like Tridion can easily handle anything from the node and attributes values in an XML to rich-text, multimedia, and more complicated sets of content. 
Other use cases:
  • states and state abbreviation list
  • departments and abbreviations or codes
  • Tridion items and their tcm-ids (ids would be hardcoded, but example could be adapted to link to items directly)
  • other mappings for external databases or information
A few of these could be handled via web services, custom code, or other Tridion integration points. However, a lot can be done with Tridion's out-of-the-box functionality. Please feel free to leave suggestions, clarification, or questions. I'll likely overhaul this with a Tridion 2011 treatment as well.

1 comment :

  1. Not everyone uses XSLT component templates, but for those that do you'll notice the script assistant namespace isn't used. It can be used to publish binaries, but it's not really needed in this example.


Feel free to share your thoughts below.

Some HTML allowed including links such as: <a href="link">link text</a>.