Archive

Archive for July, 2009

Poem: Love is Possible

July 29, 2009 Leave a comment

This is one i wrote today: 29/07/2009  (on the way to work).

~ Love is Possible ~

Walking down the street alone
The throng around me pulses
A pretty girl passes by
Is there a small smile for me
Hiding in her weary expression?
Walking resumes, I never stopped
Nevertheless I resume.
The letters on the street wall say:
“Love is Possible”
No question mark, it’s just there
Why do the letters seem to quiver?
Three little words
Words giving hope, words obliterating consciousness
Do these words lie to me?
Go on walking, I didn’t stop
Yet I continue.
“LOVE IS POSSIBLE”
I shout to the foggy air
There is no doubt in the sound
Then why does my voice quiver?
The echo seems to mock me
Did my heart lie?
Is that the sun behind rolling clouds?
Will it shine for me?

Categories: Poetry Tags: , , ,

Poem: In Love’s Defense

July 18, 2009 Leave a comment

This one i wrote today: 18/07/2009.

Enjoy.

~ In Love’s Defense ~

In love’s defense,
she was here first
Long before we came along
She was never ours to hold
She never belonged to us
but to the world
Belonged to the butterflies’ wings
and to the tree tops’ wind
Our claim on her was never just
All our praises never enough
In Love’s defense,
She never presumed to be more
than what she is
Never asked for anything in return
Not once ridiculed our ethereal groping
Her light continues to elude
our ever present darkness
She dances between music notes
Swims in life’s deep currents
She is free
for us to enjoy
She is here
for us to share
Never own
In love’s defense -
She is LOVE.

Categories: Poetry Tags: , , ,

Implementing the XSLT Mediator – Part 2

July 17, 2009 18 comments

Contents

Introduction

In the previous article I’ve discussed the fundamentals of setting up the XSLT Mediator, configuring it and then showed how to create a simple compound component template which is making use of an XSLT TBB.

In this article I would like to concentrate mainly on extension objects; a little bit on what they are and how to make use of these in conjunction with the mediator.

.NET XSLT Extension Objects

The .NET Framework allows us to extend the style sheets we build by creating Extension Objects, these can be simple classes that contain helper or utility methods.

Some functionality is either extremely difficult or impossible to implement in pure XSLT code, for example we may want to retrieve a list of items from Tridion, doing this in just XSLT will be complicated and unmanageable to say the least.
The extension feature allows writing the logic for this kind of functionality in .NET managed code, we may even already written this code for a different part of our implementation and we simply want to reuse it.

If this concept is still unclear I am sure it will become more so further in the article, I will also add some links to other resources on the web that cover this area more thoroughly.

Creating an Extension Object

We’ll begin by creating a simple class with some useful methods that we can reuse in multiple templates:


using System.Text;
using System.Xml;
using Tridion.ContentManager;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Publishing.Rendering;
using Tridion.ContentManager.Templating;

namespace Tridion.Extensions.Templating.XsltHelpers
{
public class SimpleXsltHelper
{
private TemplatingLogger m_Logger = null;
private Engine m_Engine = null;

public SimpleXsltHelper(Engine engine)
{
m_Engine = engine;
m_Logger = TemplatingLogger.GetLogger(this.GetType());
}

///
/// Returns the result of rendering the provided component and compomnent tempalte in a xml document
///component = the TCM URI of the component
///componentTemplate = the TCM URI of the component template
public XmlDocument RenderComponentPresentation(string component, string componentTemplate)
{
StringBuilder sb = new StringBuilder();

using (XmlWriter xWriter = XmlWriter.Create(sb))
{
xWriter.WriteStartElement("result");

TcmUri compURI = new TcmUri(component);
TcmUri ctURI = new TcmUri(componentTemplate);
xWriter.WriteRaw(m_Engine.RenderComponentPresentation(compURI, ctURI));
xWriter.WriteEndElement(); //result
}

XmlDocument resultDoc = new XmlDocument();
resultDoc.LoadXml(sb.ToString());
return resultDoc;
}

/// Used to publish a binary to the presentation server
/// compURI = the TCM URI of the multimedia component to publish
/// Returns the publish path of the binary
public string PublishBinary(string compURI)
{
Component comp = m_Engine.GetObject(compURI) as Component;

string publishPath = comp.Id;

if (comp.BinaryContent != null)
{
Binary pubBinary = m_Engine.PublishingContext.RenderedItem.AddBinary(comp);

m_Logger.Debug("PublishBinary: published Binary: " + comp.Id + " to url: " + pubBinary.Url);

publishPath = pubBinary.Url;
}
else
m_Logger.Warning("PublishBinary: " + comp.Id + " is not a multimedia coomponent");

return publishPath;
}
}
}

Here’s an explanation of the code:

The constructor of the class accepts a single parameter, an instance of the Engine (Tridion.ContentManager.Templating.Engine) class.

RenderComponentPresentation(string component, string componentTemplate) – this method accepts the TCM URI of a component and the TCM URI of a component template, renders the two and returns the resulting content in an xml document.

PublishBinary(string compURI) – this method accepts the TCM URI of a multimedia component and using the AddBinary method makes sure the binary is published to presentation server. The method returns the relative path of the published binary file.

The reason for creating this class is to be able to call the methods defined in it from an XSLT TBB, the next couple of sections demonstrate ways of accomplishing this.

Using Extension Objects – The Old Way

When I released the XSLT Mediator there was only one way for adding extension objects. To add an object to the transformation we had to create the class in the Mediator’s assembly project and inject the line of code for adding the object into the mediator’s class.

I’ve later improved this a bit by making the method in charge of adding extension objects Virtual so a developer can create their own mediator inheriting from the Tridion.Extensions.Mediators.XsltMediator and overriding that method.

So a project with a custom extension object will look something like this:

xslt mediator part2 - xslt mediator solution

In the image above you can see the helper class (which we’ll use as an extension object) and the custom mediator inheriting from the XsltMediator.

The code for our custom mediator will look like this:

using System.Xml.Xsl;
using Tridion.Extensions.Mediators;

namespace XSLTMediator.Tutorials
{
public class MyCustomMediator : XsltMediator
{
protected override void AddExtensionObjects(XsltArgumentList arglist)
{
SimpleXsltHelper helper = new SimpleXsltHelper(this.Engine);

arglist.AddExtensionObject("http://www.tridion.com/customhelper", helper);

base.AddExtensionObjects(arglist);
}

}
}

The code is very straightforward, We override the virtual method AddExtensionObjects which accepts a single parameter of type System.Xml.Xsl.XsltArgumentList.
To the arglist parameter we can add our extension objects using its method AddExtensionObject(string, object).
The method expects two parameters, the first, a String, which should contain a unique namespace within the transformation. This can be just about any string of characters you decide to use as long as its unique.

The second parameter is the actual extension object which is an instance of the SimpleXsltHelper class we created earlier.

The last line of code to mention is

base.AddExtensionObjects(arglist);

This makes sure that the helper extension object which is bundled with the mediator is also available in the transformation. If you don’t plan on using this helper object you can simply omit that line of code from your implementation.

To be able to start using our new extension object there is one last step which is needed. In the previous article I’ve showed how to configure the basic mediator in the Tridion configuration file.

First build the project and overwrite the existing Mediator DLL file with the new build.

Since now we have a new custom implementation of the mediator we need to configure this new class name instead.

So in the Tridion.ContentManager.config file change the type attribute of the XSLT mediator from: Tridion.Extensions.Mediators.XsltMediator to XSLTMediator.Tutorials.MyCustomMediator
(the namespace and class name will obviously be different in real implementations).

Make sure you restart all the necessary services as explained in the first article.

Now we can go ahead and use the new methods we created in our XSLT templates.
We will go on and extend the XSLT template used in the previous article:

<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:customHelper="http://www.tridion.com/customhelper"
xmlns:image="http://www.tridion.com/ContentManager/5.0/DefaultMultimediaSchema" exclude-result-prefixes="msxsl simple customHelper">

<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="customHelper:PublishBinary(simple:image/@xlink:href)"/>

</xsl:attribute>

</xsl:element>

</xsl:template>

</xsl:stylesheet>

First thing to notice is the declaration of the helper class namespace at the top:
xmlns:customHelper=”http://www.tridion.com/customhelper&#8221;. The important part is the namespace itself, it should be exactly the same as the one used in the Mediator’s code.
The prefix we assign this namespace can be anything we decide on as long as its unique within the context of our template.

The second part to notice is the call to our PublishBinary() method, using the prefix defined previously we can call any public method defined in the extension object’s class (As long as we use valid parameter data types). Since this method returns the publish path of the binary being published in our example we can use the returned value to set the ‘src’ attribute of the ‘img’ HTML element.

Publish Binary from XSLT code

Notice that this time when we execute the compound template there is no need for the default finish actions, the image is published by the XSLT Template and the extension object.

Hopefully this simple example shows how extension objects can be used to augment XSLT templates in such a way that provides a very robust and manageable model.

Using Extension Objects – The New Way

As can be seen from previous sections its quite simple to create XSLT templates for compound templates and even add custom logic in the form of extension objects.

One thing bothered me about this process and that is that this type of templating model basically forces managing code in two locations, two projects: one is the templates projects which is uploaded into Tridion using the assembly upload tool and the second is the Mediator project which during a project and/or implementation is updated with extension objects and helper methods.
These two projects have to be maintained separately even though they both contain functionality which is ultimately used for one purpose – templates.

Because of this issue I came up with a new and in my view better way of creating and maintaining extension objects. This way allows you to create the class(es) in the same project you develop your templates.
The Mediator then loads the extension object(s) from Tridion in a similar manner to how Tridion loads .NET templates.

Using this new way you no longer need to keep updating the Mediator project, you can simply use the provided mediator as is.

To create extension objects in the Templates project you need a few things, if you are using the base project (available on world) you’ll have an easier time because everything you need is provided there.

First, any class which is meant to be used as an EO (Extension Object) should implement an interface, this is an interface you can create yourself or you can use the one in the base project, IXsltHelper. it doesn’t really matter which interface it is actually as we will see in a minute.

The second thing needed is to decorate any class used as an EO with an attribute class, TridionXSLTHelperNSAttribute. This attribute is used to define the namespace the EO will be assigned with when inserted into the argument list.
If you’re not using the base project or using an old version of it, simply download the new project from SDLTridionWorld and copy the TridionXSLTHelperNSAttribute class file to your project.

Your project should have similar elements to this example:

.NET Templates Project

Since we already created a sample extension object we can reuse it by adding it to our templates project.
We will need to modify it a bit to conform to our new style:

using System.Text;
using System.Xml;
using Tridion.ContentManager;
using Tridion.ContentManager.ContentManagement;
using Tridion.ContentManager.Publishing.Rendering;
using Tridion.ContentManager.Templating;
using Tridion.Extensions.ContentManager.Templating;

namespace Tridion.Extensions.Mediators
{

[TridionXSLTHelperNS("http://www.tridion.com/customhelper")]
public class SimpleXsltHelper : IXSLTHelper
{
private TemplatingLogger m_Logger = null;
private Engine m_Engine = null;
.
.
.

Notice that now the SimpleXsltHelper is implementing our IXSLTHelper interface and has the TridionXSLTHelperNS attribute. The value we pass the attribute is the same namespace we used earlier so that means there is no need to change the XSLT at all.

The mediator will take care of the rest, but to make sure it does we need to add a few configuration parameters to the Tridion.ContentManagaer.config file in this fashion:


<mediator matchMIMEType="text/xml" type="Tridion.Extensions.Mediators.XsltMediator" assemblyPath="C:\Program Files\Tridion\bin\Tridion.Extensions.Mediators.dll">

<parameters>
<parameter name="loadFromTridion" value="true"/>
<parameter name="interfaceName" value="IXSLTHelper"/>
<parameter name="templateID" value="tcm:42-15958-2048"/>
</parameters>
</mediator>

Let’s go over the parameters:

loadFromTridion: True or False telling the mediator whether to look for extension objects in Tridion.

interfaceName: The Mediator loads the assembly for Tridion and will look for classes that implement an interface with this name.

templateID: The TCM URI of the template building block containing the templates assembly.

As always make sure to restart all the necessary services after making the configuration changes.

From now on you can create and modify your extension objects as if they were any other .NET template you were working on. Updating the code in Tridion requires the same process as do normal templates and there are no extra steps needed.
It also means you have only one project containing all your templating functionality code which I think is a massive improvement.

Templates Project With Helper

Running our compound CT again gives us the exact same result as before:

Using new way of extension objects

XSLT Page Template

Up until now we have been working on a compound component template that was using a XSLT TBB but it wasn’t doing much more than what could be accomplished with normal XSLT CT.

Here is an example of a simple XSLT page template:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:tcm="http://www.tridion.com/ContentManager/5.0"
xmlns:customHelper="http://www.tridion.com/customhelper"
exclude-result-prefixes="msxsl customHelper">

<xsl:output method="html" indent="yes" omit-xml-declaration="yes"/>

<xsl:template match="/">
<html>
<head>
<title>
<xsl:value-of select="tcm:Page/tcm:Data/tcm:Title/text()"/>
</title>
</head>

<body style="background-color:yellow;">
<xsl:for-each select="tcm:Page/tcm:Data/tcm:ComponentPresentations/tcm:ComponentPresentation">

<p>

<xsl:variable name="cp" select="customHelper:RenderComponentPresentation(tcm:Component/@xlink:href, tcm:ComponentTemplate/@xlink:href)"/>

<xsl:copy-of select="$cp/result/node()"/>
</p>

</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

As with the Component Template created in the first part of this tutorial, you will need to create a XSLT TBB and paste the above code into the source pane, then create a new compound page template in the Template Builder and add the new XSLT TBB to the list of selected templates.
Save and close the new PT and create a new page based on this page template.

Now we can preview our XSLT page template successfully:

XSLT Page Template

Very easily we created a new page template in XSLT, to render the component presentations on the page we use a method we added to the extension object which returns the resulting content and layout in an XML document that is stored in a variable from which we can copy it onto the page.

Conclusion

In this article I focused mainly on creating extension objects and using them from XSLT templates.
I showed two ways of including extension objects in the transformation of templates, both are valid but the second is much more convenient in terms of deploying and managing the functionality of extension objects..

I’ve even added a simple example of a XSLT page template which is where the benefit of using the XSLT Mediator is really obvious since Tridion doesn’t support this type of template natively.

The XSLT Mediator comes with an extension object which is added to the transformation by default. The namespace for this object is: “http://www.sdltridion.com/ps/XSLTHelper

This default object comes with some useful methods:

getFormatedDate – Generic XSLT helper function to format date strings using standard format strings.

getListItems – Generic XSLT helper function to retrieve items from within an OrganizationalItem

GetMultimediaInfo – Returns xml with information about the MM component such as the mime type or extension

Source Code

Can be downloaded here.

Resources

Billie Jean Cover by David Cook

July 16, 2009 Leave a comment

In case you haven’t heard this cover of Michael Jackson’s “Billie Jean” by David Cook (winner of American Idol Season 7) then take my strong advice and listen to it here.

In my view if this is not the best cover ever made it most definitely comes close to it.

This is one of those covers that completely suppress the original song and takes into a whole new level.

Like most people i used to be a huge MJ fan, i had all of his cassettes (yes! cassettes!) and i would occasionally sin and try to do the moon walk in my room :) But Billie Jean was not one of my favorites, the lyrics were of course great but i never connected to its rhythm or its melody.

However listening to Mr Cook’s rendition – the power and energy he delivers his version of the song with is to me completely astonishing, its like a punch in the stomach only in a good way.  The cover transforms the song into a very powerful, mysterious and grabbing musical event.

So Simply click Play and hear for yourself…

What do you think?

Implementing the XSLT Mediator – Part 1

July 11, 2009 4 comments

Contents

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

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

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

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

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

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

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&#8221; 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

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.

Poem: Flame of Creativity

This poem i wrote in the summer of 2001.

I wrote it on a piece of napkin at this very quaint restaurant in Poland, we were on a family trip to Poland and we were sitting at this authentic restaurant for dinner with stuffed dear heads on the walls, on the table there was a dripping candle and at that moment this poem was born.

Hope you enjoy it. Feel free to leave me a comment to let me know what you think about it.

The standard disclaimers apply, the poem was originally written in Hebrew therefore the translation may lose or change some of the meanings, rhyming, wordplay, etc.

~ Flame of Creativity ~

New flame, darkness gone
Pure flame, abundant light
Flame flickers, storm outside
Red flame, candle burning

First wax drip
Then one more
Pouring without cease

Flame died
Candle dwindled

Darkness.

The original Hebrew version:

~ להבת היצירה ~

להבה חדשה, החשכה נעלמה
להבה טהורה, נדלקת ומאירה
הלהבה רועדת, בחוץ סוער
להבה אדומה, הנר בוער

טיפת שעווה ראשונה
עוד אחת אחריה
זולגות ללא הפסקה

הלהבה כבתה
הנר דעך

חשכה.

Categories: Poetry Tags: , , ,
Follow

Get every new post delivered to your Inbox.

Join 302 other followers

%d bloggers like this: