1) Ordered Pair - embeddable schema Consisting of two items:
- key (text)
- value (text)
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:
http://www.example.com/schemas/listorderedpair)
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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant"
xmlns:listorderedpair="http://www.example.com/schemas/listorderedpair"
exclude-result-prefixes="xsl tcm xlink tcmse listorderedpair">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
<xsl:template match="/">
<values>
<xsl:apply-templates select="/tcm:Component/tcm:Data/tcm:Content/*" />
</values>
</xsl:template>
<xsl:template match="*">
<xsl:for-each select="//listorderedpair:orderedpair">
<value>
<xsl:attribute name="key">
<xsl:value-of select="listorderedpair:key" />
</xsl:attribute>
<xsl:value-of select="listorderedpair:value" />
</value>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:tcmse="http://www.tridion.com/ContentManager/5.1/TcmScriptAssistant"
xmlns:listorderedpair="http://www.example.com/schemas/listorderedpair"
exclude-result-prefixes="xsl tcm xlink tcmse listorderedpair">
<xsl:output method="xml" indent="yes" omit-xml-declaration="no" />
<xsl:template match="/">
<values>
<xsl:apply-templates select="/tcm:Component/tcm:Data/tcm:Content/*" />
</values>
</xsl:template>
<xsl:template match="*">
<xsl:for-each select="//listorderedpair:orderedpair">
<value>
<xsl:attribute name="key">
<xsl:value-of select="listorderedpair:key" />
</xsl:attribute>
<xsl:value-of select="listorderedpair:value" />
</value>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
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
next
%]
'component and corresponding component template that outputs actual xml via XSLT is required
for each comp in page.componentpresentations
writeout comp.content
next
%]
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:
<values> <value key="1">First Value</value> <value key="2">Second Value</value> </values>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.
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.
ReplyDelete