Archive
One Extension to Rule them All
Since Tridion 2011 has been released with its shiny new GUI framework everyone and their sister have either been creating or thinking about creating extensions. I myself have been heavily involved in creating some.
Traditionally, extensions for the most part are islands of functionality; code is typically hardly ever reused. This is something I’d like to improve. With the advancement of the Tridion framework and by following OO practices, it’s possible to create reusable code, frameworks and more, the sky it the limit really.
A few weeks ago I thought about customizing GUI extensions. As extensions mature it will make sense to allow Tridion users, whether administrators or business, the ability to make changes to extensions’ behavior, to turn functionalities on and off and more, without having to change the underlying code. This led to… *drumroll* … The Extensions Manager.
Setting up a Tridion 2011 GUI extension in 8 steps
The new 2011 Tridion GUI framework is a major overhaul to the way extensions have been previously developed. The framework now is far more robust and well designed. Building new and exciting extensions has never been easier. However, configuring your extension may not be the easiest thing in the world to do…
The following tutorial steps show how to configure an extension for the Tridion 2011 GUI from start to finish.
The example configuration and code is based on my extension: The Item XML Display.
My First Attempt at Tridion 2011 GUI Extensions
About a month ago I happily shared a GUI extension I’ve built for Tridion 2009 called the Item XML Display extension.
This extension lets a user (typically a developer) view the entire XML structure of a Tridion item from within the GUI without the need to open a new IE window or having a remote session to the CM server.
If you’re one of those already using this extension and have been dreading the moment Tridion 2011 will come out and you will be left without being able to quickly view items’ XML, fear not! I got you covered:
The Item Xml Display Tridion GUI Extension
Continuing my recent trend of Tridion GUI extensions,
- Using jQuery for Tridion GUI Extensions.
- Integrating Tridion with Gravatar.
- The Read-Only Fields Tridion GUI Extension.
I give you the “Item XML Display” extension:
Integrating Tridion with Gravatar
Lately I’ve worked on a Gravatar library for .NET which I released in July. I have also recently had the chance to work on Tridion GUI extensions for a customer.
This got me thinking; wouldn’t it be cool to integrate the two? Almost immediately I thought; yes, it will be cool!
So I’ve set to work on a nice GUI extension that will bring Gravatar to Tridion users and give the GUI a bit of a social touch make it feel more personalized by displaying a personalized photo for each user.
And so the integration is really 3 different extensions that can be each used individually or together.
Current User Photo
The first integration shows the Gravatar photo for the current user logged on to the Content Manager Explorer:
Implementing the XSLT Mediator – Part 1
Contents
- Introduction
- Setting up the Mediator
- Creating an XSLT Component Template
- Component Linking
- Conclusion
- Source Code
Introduction
In the next series of articles I plan on showing how to use the XSLT Mediator which Im currently maintaining as an eXtension available on SDLTridion World.
The Mediator can be downloaded from the XSLT Mediator Page
An explanation why should you use the XSLT Mediator can be found at the aforementioned download page, so I won’t go into that, ill simply show how it can be used.
This is the first part in a series of at least 3 articles; in following articles I will mainly be discussing how to extend the XSLT transformation with .NET code.
This article assumes basic knowledge of XSLT and basic Tridion experience in templating.
Setting up the Mediator
In the Mediator zip file you will find the assembly DLL which can be used as is as well as the source code of the mediator project.
You should be able to simply drop the DLL somewhere on the Content Manager Server to begin using it but you may choose to first use the source code either to build it against a different version of Tridion (currently that’s 5.3GA) or if you wish to add extension objects to the assembly (will be discussed on the next article in this series).
The simple setup requires an edit to the Tridion configuration file, which is located in the Config folder under the Tridion installation folder (i.e.: C:\Program Files\Tridion\Config) and the file name is Tridion.ContentManager.config.
Open the file for editing and insert the following XML fragment in the <mediators> element:
<mediator matchMIMEType="text/xml" type="Tridion.Extensions.Mediators.XsltMediator" assemblyPath="C:\Program Files\Tridion\bin\Tridion.Extensions.Mediators.dll"/>
If you’re using the binary as it is supplied then there is no need to change the ‘type’ attribute but make sure the ‘assemblyPath’ attribute is pointing to the right location of where you placed the DLL file.
To begin using the Mediator you should restart the following: Tridion COM+ package (Component Services), IIS, Tridion Publisher service and any open Template Builder instance.
Next step is to create the parameters schema which will be used with the XSLT TBBs we will be creating.
In the zip file you will find XSLT_Transformation_Parameters.xsd, In Tridion create a new parameters schema and use the upload button in the source tab to load the contents of the included XSD file:

XSLT transformation parameters schema
That’s it. This is all the setting-up needed for now.
Creating an XSLT Component Template
Now you’re ready to create your first XSLT TBB which can be used in a compound template.
Note: For a long time it was possible to create XSLT component templates in Tridion, this has not changed. XSLT page templates however are not supported so in order to create these, the Mediator is required. The Mediator has another advantage of being able to incorporate managed (.NET) code into XSLT templates (will be discussed in a later article).
Lets create a simple schema which you will be able to use to test your new XSLT template with.
(The schema is included in the downloadable for this article)

Simple Schema
The schema contains a title text field, a body rich text field, a date field and a multimedia link for an image.
Create a new component based on this schema and populate its fields with some values.
Based on this schema we will start with a simple XSLT TBB which we can extend later on:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:simple="uuid:3CC625ED-34E6-4B51-BDD8-72BBD0D71469" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
exclude-result-prefixes="msxsl simple">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:element name="p">
<xsl:apply-templates select="tcm:Component/tcm:Data/tcm:Content/simple:Content"/>
</xsl:element>
</xsl:template>
<xsl:template match="simple:Content">
<xsl:element name="h3">
<xsl:value-of select="simple:title"/>
</xsl:element>
<xsl:element name="div">
<xsl:copy-of select="simple:body"/>
</xsl:element>
<xsl:element name="div">
Publish Date: <xsl:value-of select="simple:pubDate" />
</xsl:element>
<xsl:element name="img">
<xsl:attribute name="src">
<xsl:value-of select="simple:image/@xlink:href"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
If you’re familiar with doing normal XSLT component templates you will notice the declaration of the “simple” namespace prefix at the top, this is necessary to be able to output the component’s content. The uuid:3CC625ED-34E6-4B51-BDD8-72BBD0D71469 namespace is copied from the schema we’ve just created (notice that each new schema receives a new target namespace by default which is in this long string format).
The rest of the template is very straight forward and just outputs the field values from the component.
In Tridion create a new TBB and copy the above code into the source tab. In the general tab make sure to add the parameters schema created before then save & close the template:

XSLT TBB with parameter schema
To use this new template open the Template Builder and create a new compound component template:

Template Builder Compound CT with XSLT TBB
You can now run the template with the component you created earlier, the result should be something like this:

Run Compound CT in Template Builder
Note: Above I mentioned that I wont go into the merits of using the XSLT Mediator but one very important thing to notice is how quick it is in comparison to the Dreamweaver Mediator, obviously this example cannot be taken into account but even in real life templates, XSLT ones out run their DW counterparts by hundreds or percent.
There is no need to fill in any of the parameters attached to the XSLT Template but lets take a moment to review these:
Input Item Name – This is the item in the package to use as the input xml for the transformation.The default item which will be used for a component template is the item with name ‘Component’, for a page template it will be the ‘Page’ item.
Output Item Name – This is the name of the item the Mediator will create in the package with the result of the transformation; the default is ‘Output’.
Get Parameters from Package – A true/false value determining whether the Mediator should include items in the package as parameters for the transformation. Default is ‘true’.
For performance purposes it is recommended to change this to ‘false’ unless you require all of the items to act as parameters or plan on using specific items by specifying a prefix.
Package Items Name Prefix – The value of this parameter tells the mediator to only use items in the package which have the specified prefix. Presuming, the value of the previous parameter is ‘true’.
For example all items in the package with a prefix of ‘_par’ will be used if this value is specified.
The mediator will strip the prefix from the actual parameter name when its added to the transformation.
Output Format Type – Which content type to use for the result item created by the Mediator Default is ‘XHTML’.
Getting back to our new template:
Notice the broken image in the last screen shot, by using some of the default TBBs provided by Tridion we can easily sort this out:

Compound Template with Image
The order in which to place these TBBs (Extract, Publish, Resolve) is critical for the image to be published and displayed correctly.
Component Linking
The XSLT Mediator supports “linking” natively in a very similar way to how it was accomplished in XSLT CTs – by use of the document() function.
To demonstrate this ability I will use a metadata field set on the multimedia component to set the alt attribute of the image element in the resulting html. First the modified XSLT TBB:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:simple="uuid:3CC625ED-34E6-4B51-BDD8-72BBD0D71469" xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
xmlns:image="http://www.tridion.com/ContentManager/5.0/DefaultMultimediaSchema"
exclude-result-prefixes="msxsl simple">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:element name="p">
<xsl:apply-templates select="tcm:Component/tcm:Data/tcm:Content/simple:Content"/>
</xsl:element>
</xsl:template>
<xsl:template match="simple:Content">
<xsl:element name="h3">
<xsl:value-of select="simple:title"/>
</xsl:element>
<xsl:element name="div">
<xsl:copy-of select="simple:body"/>
</xsl:element>
<xsl:element name="div">
Publish Date: <xsl:value-of select="simple:pubDate" />
</xsl:element>
<xsl:element name="img">
<xsl:attribute name="alt">
<xsl:value-of select="document(simple:image/@xlink:href)/tcm:Component/tcm:Data/tcm:Metadata/image:Metadata/image:altText"/>
</xsl:attribute>
<xsl:attribute name="src">
<xsl:value-of select="simple:image/@xlink:href"/>
</xsl:attribute>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
The interesting additions are in red, first add the namespace of the multimedia schema, in this case this is the default MM schema, We use ‘image’ as the prefix.
Then add a definition for a second attribute to the ‘img’ element, in the example we use the document function to load the entire multimedia component’s XML by passing the xlink:href attribute of the link field, this attribute’s value is the TCM URI of the image component. (In the content component the link is stored like this: <image xlink:type=”simple” xmlns:xlink=”http://www.w3.org/1999/xlink” xlink:title=”chrome” xlink:href=”tcm:42-15992″ />)
We then use an inline XPATH statement to get to the altText metadata field.
The result of this can be seen here:

XSLT CT - component links
With the document function we can successfully retrieve information from any other Tridion item as long as we know its ID (TCM URI).
Conclusion
It is very easy to set up and start using the XSLT Mediator, it provides both flexibility and speed which are not catered so well by the Dreamweaver mediator and for customers wishing to make use of an XSLT based solution it gives the possibility of using XSLT templates for components and pages alike.
However this article does not show some of these advantages, In the second part of this series I will look into:
- Extending the XSLT transformation with extension objects
- Using Extension objects to publish binaries, render component presentations, etc.
- Creating an XSLT Page Template
Source Code
You can download the example XSLT and Schema here.



