Sitecore XSLT guide for beginners – Part 1 – Terminology

Welcome you n00bs and newbies!
It’s time to explore the wonderfull world of XSLT :). Are you ready? Today will be a very intensive day, but don’t worry, you’ll see the result within an hour ;-).

No serious now. XSLT is very though for most developers. I’ve seen it by myself, but have also seen that you should be able to become a master by yourself. We’ve started with some XSLT in Sitecore but after a couple of renderings, we’ve decided that we should have more flexible environment to create our websites in. So we changed everything to WebControls, UserControls, etc. We’ve never looked back at XSLT, or jsut a second and continued writing code.
Around middle 2006 the focus came a bit more on quality of code and improving the speed of out development. So we decided to investigate what’s the best way to create your pages and we’ve seen that in lots of circumstances XSLT is very usefull, fast and also(most important): bugfree! For
using XSLT I’ve created this scheme, which is still valid and used inside LECTRIC.

But what to do when you don’t have any experience with XPath, XSL(T), etc? Well, then come to Alex and sit back and learn!

To start, we’ve to become familiar with the concepts of XML, Validation, Namespaces and XPath. To be sure we’re on the same level, let’s (re-)introduce them:
XML: I hope you do know what XML is. It’s a simple form of storing data, you can order the data in the way you want, you’re not really limited to tags. You’re not really possible to create links to other documents, or do some internal linking as basic functionality of XML. The following piece of well-formatted XML:

<blogger>
<name>Alex</name>
<age>20</age>
<publicProfile>true</publicProfile>
</blogger>

When this is your first introduction into XML, walk carefull to the basic XML-pages on W3Schools.

XML Validation: XML validation can be done is several ways. The reason to validate your XML is pretty simple, you want to make sure you can trust a document and that it is formatted in a way you do expect. In my opinion there are 2 kinds of validation:

  1. Structure validation, which checks if you use the right XML-nodenames, the right identing, etc. For example, you do expect a blogger to have a name-tag such as the example above.
  2. Data validation, which checks if the nodevalues are valid. Take the above example, you want to be sure that’s the age-node contains a numeric value.

The first one is the best implemented in DTD’s(Document Type Definition). But the syntax is definitelly hard to understand and to maintain. Your tutorials to become familiar with DTD can be found here or ofcourse at the W3Schools. It’s not really a requirement for becoming XSLT-expert, but it’s a very good addition to your knowledge and the global knowledge of XML related technics.
The second one of validation combined with a little less powerfull way of the first validation is done by XSD’s(XML Sheet Definition). Using XSD’s, you validate XML using XMLs. XSD are quite hard to create when you are starting with using XML. Creating XSD’s isn’t that important, it more important that you can read XSD’s, as this allows you to understand XML Namespaces for example and gives you the possibility to figure out why your XML-document isn’t validated. The best guide to become familiar with XSD’s is again W3Schools.

XML-Namespaces: And advanced option of XML is the usage of namespaces. Namespaces allow you to create nodes with other names, but with a different prefix. For example(xmlns means XML Namespace):

<blogger xmlns:blogger=”http://www.blogger.com/profile” xmlns:blog=”http://www.blogger.com/blog”>
<blogger:name>Alex</blogger:name>
<blog:name>.Sitecore</blog:name>
<blogger:age>20</blogger:age>
<blogger:publicProfile>true</blogger:publicProfile>
</blogger>

As you can see, I do use the same node-name(‘name’) 2 times. But it are different fields as they reffer to another namespace. You might have also noticed that the namespaces are URI’s. For futher explanation and some real-life examples, look here.

XPath: When you’re able to create a well-formed, validated, and nice seperated XML-file, you want to access the data. Therefor, our friend of the World Wide Web Consortium have created a kind of query-language called XPath. It’s a really simple syntax which allows you to easily access any node inside your XML from any place. The tutorial is again available at W3Schools, over here.
One of the hardest parts of XPath is Axes. You might need them a lot. To help you a little, Sitecore has published some additional information on SDN. But you need Developer Access to SDN, sorry!

Editing XML: There are several tools to edit XML. I do recommend Visual Studio or XML Spy as both supply very nice highlighting and tools to create and edit XML in a simple and fast way. But poor old notepad, in combination with a browser to do the highlighting after saving, will also do the tric! πŸ™‚

Allright, that was ought enough for today. Tomorrow, I’ll continue with the first steps on converting. Afterwards a third posting will be done on friday or saturday which finalize this short course.

MondoSearch integration *Updated*

Today, Allan Thræn has published an excellent article on the MondoSearch integration in Sitecore. A couple months ago, as lead-engineer of the product, Allan gave my colleague Ben and me a cool demo of the Sitecore 5.2 based integration of MondoSearch. We we’re happily surprised! It’s a wonderful, easily configurable and maybe even more important, very fast module. Next to it, Allan is very nice chap. He answered very patient all our questions and we’d even some time to laugh.
These days, the 5.3 integration seems to be ready and it really becomes time to pay some attention to this module. It’s more expensive then dtSearch for example is, but is has much more functionality. So I promise, before the end of February, I’ll take a further look at it. For this moment, just have a look at the following blog articles of Allan:

By the way, his blog is it worth to becomes a part of your opml.

Update: I’ve added part 3 of the series. And updated some brandnames ;).

Test migration 5.2 -> 5.3: Migration module and rebuild of the code

As described here, I’m investigating what kind of problems to expect when we migrate a website from 5.2 to 5.3. As I got some time left today, I’ve decided to continue work on the project.

Migration module:

First I’ve investigated how the Migration module worked. This summary stood on SDN:

Data Migration module allows transferring data from the former versions of Sitecore to later Sitecore releases (see the Supported Sitecore Versions section). The module does not convert the databases; it extracts all the data and puts it into the new database.
The module requires two Sitecore installations working simultaneously – the source installation and the target installation. Please refer to the Module Architecture section for more information on how the module works.

The way the module works internally is described pretty simple to:

Data is transferred from the source Sitecore installation to the target installation via a web service. The web service is supplied with a special service package which is installed on the source installation. This service provides a kind of portal for data transfer.

That’s pretty clear enough. The other information described I’ve to install something on the original and the new environment. They have to work together. It would be good to use  2 machines outside a production environment to do the first tests. It can be done on 1 machine, but make sure you aren’t abusing other users(such as other developers or testers) with your huge amount of datatransfer, database and resource usage.

Rebuild of the code:

Figured out that the following order is one of the best ways to perform the upgrade. There are some really clear test moments. Before you read this, read carefully to the end of all lines, so you don’t mix up some steps, even ignore the stop here’s…

  1. Don’t mix up your head! Don’t refactor, change your code to XSLT, etc. You’re not building a framework buddy, you’re upgrading that’s worst enough! πŸ˜‰
  2. Build against new Sitecore.Kernel. There are some little API changes, some may brake the code. Don’t go and change heavy code stuff. The maximum of lines you’re allowed to change is 2 at once. When other functionality is broken, comment it out and add a ‘FIXME’ as a comment.
  3. Locate Media Library usage. No code should be broken, but mark them again for fixing.
  4. Migrate config-values to Site Specific Configurations or the way you want to setup your config values.
  5. This is the moment you’ve to focus on your content. Stop here until your test-content-migration with production data is ready.
  6. Resume when your content is proper migrated(will come back later on that). It’s time to test some general functionality. What’s good what’s bad? List ‘m and make sure which are already marked in code with FIXME’s. Make sure that collaboration such as Sharepoint connectors, LDAP’s, custom data-adapters, etc, aren’t migrated yet. But do count those as problems.
  7. The FIXME’s are mostly not that bad to solve. Walk trough the list and apply changes. Stop with a single one when it takes more then 15 minutes to resolve it. You have do re-look later. After that, fix the stuff and update your buglist(should be at maximum 25% of what it was).
  8. Integrate and activate modules one by one. Do the same for custom adapters. Do the same as the other fixes, when it does take more then 15 minutes to make it build or fix it, leave it for later. List the issues you’ve got.
  9. Retest everything, especially the issues which are on the list. Is everything still an issue?
  10. Now take a look at your issuelist. Those are the real migration issues. Predict how much time the issues will take. Group similar. Check release notes of the modules and Sitecore. Ask for help on the Sitecore forum.
  11. Retest everything. You should be ready now.

Although these 11 steps seem to be enormous, I can tell you, migrating to 5.3 isn’t a hell at all. I didn’t need to rewrite any code to get everything building. I also only had to change Media Library code on 5 places. Migrating my configuration values seems to be a piece of cake, haven’t been able to do that.
Tomorrow it’s up to the content and after that the LDAP module, dtSearch and the Forum module. When finished, it might be good to write something about deployment. But should not rush as  I don’t know what the day of tomorrow brings to the small city of Zaltbommel in the Netherlands.

Test migration 5.2 -> 5.3: Why and how…

For one of our customers, I’m going to do a test migration from Sitecore 5.2 to 5.3 the rest of today and tomorrow. The goals of the test migration:

  • Find out what’s the main problem: code or content
  • Find out how many time is exactly spent when upgrading the original databases to a new, 5.3 version
  • Check which CMS-changes has to be done
  • Look at the possibility to replace parts of the code with Sitecore code

So that are the goals. Now the reason to do this study before the final upgrade. Well that’s quite obvious, the customer asked us to assess the time it would take to upgrade from 5.2 to 5.3 and I thought it should be possible within 9 days. And ofcourse they expected it to be faster, so they give me one day to show I was right or totally wrong.

My plan:

  1. Figure out how the Migration module exactly works
  2. Build the solution of the customer against the 5.3 Sitecore.Kernel.dll. Afterwards look at the errors, etc.
  3. Build our own custom components which are converted yet against Sitecore(such as custom fields, etc).
  4. Look at XSLT forward-compatability
  5. Set up a clean 5.3 instance on a development machine
  6. Prepare content conversion by installing the Migration module
  7. Preform migration with 10% of the Media Lib Items(are the biggest problems as they should be inserted in the database)
  8. Walk trough CMS, check for problems
  9. Figure out how much should be converted between master and shared values, etc
  10. Refine the time I need to do the full upgrade

How much time will these steps take:
1: 0,5 hour
2 – 4: 2,5 hours
5 + 6: 0,5 hour
7: 2 hour
8 + 9: 1,5 hour
10: 1 hour

That’s a total of 8 hours. And have to do a presentation tomorrow between those hours… hmmzz, guess it becomes quite busy! Stay tuned for more info!

Some more community updates…

This time some really cool movies on Channel 9:

That’s it for now. I might do some additional blogging later today…

Microsoft community updates

Yes it’s time to do an update on Microsoft. They are incredible busy. And they are releasing like no other company is able. Make sure you got a minute or 60 to explore all these features! Just grap another cup of coffee before you start! Because here’s the summary of January:

  • Orcas update: the January CTP is released. There are 2 downloads. One containing the installer and one on the regular Virtual machine. I’m going to wait until the next CTP(February) as again downloading 6Gb will be way to much work for me. Here are the (hidden) release notes located and here the public(blog-o-sphere). Some people are a bit confused, is this the December CTP? Actually it isn’t as modification are made later, but some parts are indeed (internally) release in February.
  • Orcas update 2: Microsoft is announcing the new cool Webdesigner. Look at this blog post of Mikhail Arkhipov. Can’t wait to get my hand on the February CTP of Orcas :D!
  • Sandcastle: Allright it isn’t January, but back in 2006 the documentation team of Microsoft has release a new version of Sandcastle. Check out here
  • Enterprise Library 3.0 update: Tom Hollander(I like his name ;)) announces this release of this brilliant piece of software. The coolest new block is the validation block. For more details on releases, read this entry by Tom.
  • ASP.NET AJAX 1.0 Released, yes finally it is! Peter, have fun! Ow yeah, Jakob, I do expect 5.4 to take advantage of it πŸ˜›
  • Expression suite is for sale. Take a quick look at their website and impress the designers at your company!
  • Software factories: Webservice and Webclient factories are released :D. My hands only have touched the second one, but I can promise, you’ll love them. Although it might be hard to that advantage of the model in your first project. But I promise, it provides a great insight in your own solutions, from a different perspective. For the freaks, read this post.
  • The Microsoft website is updated today as Alexey writes about.

That’s it for now. Going to play tennis for a moment :D…. Brrrrrr cold πŸ˜‰

Missing pipeline classes?!

Was writing an article for you guys about pipelines in Sitecore 5.3… And found out that I’m missing some classes in the .CHM.
For example, take those 3:

<getMediaStream>
<processor type=”Sitecore.Resources.Media.ThumbnailProcessor, Sitecore.Kernel”>
</processor>
<processor type=”Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel”>
</processor>
<processor type=”Sitecore.Resources.Media.GrayscaleProcessor, Sitecore.Kernel”>
</processor>
</getMediaStream>

Only the ResizeProcessor is available in the .CHM. The Reflector provides me the reason: the ThumbnailProcessor and GrayScaleProcessor seem to be internal. But why? And as they are used as processors and configured in the Web.config, why would you make ‘m internal?

And in the same namespace, the HttpHandler ‘MediaRequestHandler’  is also internal. I can imagine 3 possible scenarios:

  1. There are some damn ugly hacks inside those classes, specific for Sitecore.Kernel/Sitecore.Client functionality. You don’t want to make the classes available as people might go and use them for their own solutions and will introduce unexpected bugs.
  2. There’s some bought or very time intensive logic inside these classes. Sitecore dóesn’t allow implementation partners to use them. But, when you are familiar with the System.Reflection-namespace, you will be able to resolve the class, I’m sure…
  3. When converting from .NET 1.1 to .NET 2.0 or at creation time, Ole has forgotten to add ‘public’ before the class-definition. And as the Sitecore.Kernel is the executing class of the pipelines, errror will not occer(Are the pipelines unit tested? When Unit Test are preformed in a right way, the visibility of the classes will crash the tests.)

That’s it for tonight. Will finish the ‘pipeline’ article later this week.

Say hi to Ben!

One of my funniest colleagues, Ben, has started his own blog about Sharepoint 2007. I do like that as we haven’t been able to explore this new Microsoft stuff a lot. And maybe more important, Ben has a little daughter and a very unpatient girlfriend ;-). So Ben is the guy you want to do the research, as he’s able to please his daughter and wife, he should be able to write easy-to-read-but-pretty-advanced articles ;-)!

Here’s the url: http://www.sharepointexperience.net/

By the way, Ben is also a part of our Sitecore team! So he might be able to bring both products a bit though each other. At least for LECTRIC…

The art of generic code

In the past I’ve posted a pretty nice example of efficient code. These days, I’ve written this incredible simple but usefull functionality for fields:

    1     public static class FieldUtil<T> where T : Sitecore.Data.Fields.CustomField

    2     {

    3         /// <summary>

    4         /// Returns a field implicit casted to the required type(T) and logs a warning in case of the field doesn’t exist.

    5         /// </summary>

    6         /// <param name=”currentItem”>Item to read the field from</param>

    7         /// <param name=”fieldName”>Field name</param>

    8         /// <returns>The casted field retrieved from the currentItem or null.</returns>

    9         /// <exception cref=”T:System.ArgumentException”>Occurs when the currentItem is null or the fieldName is null or empty the method return.</exception>

   10         public static T GetField(Item currentItem, string fieldName)

   11         {

   12             if(currentItem == null)

   13             {

   14                 throw new ArgumentException(“The argument with the name ‘currentItem’ cannot be null.”);

   15             }

   16             if(string.IsNullOrEmpty(fieldName))

   17             {

   18                 throw new ArgumentException(“The argument with the name ‘fieldName’ cannot be null or empty.”);

   19             }

   20 

   21             T result = null;

   22 

   23             if (currentItem.Fields[fieldName] != null)

   24             {

   25                 result = currentItem.Fields[fieldName] as T;

   26             }

   27             else

   28             {

   29                 string warningMessage = string.Format(“Couldn’t find field with the name ‘{0}’ in item with the id ‘{1}’.”, fieldName, currentItem);

   30                 Sitecore.Diagnostics.Log.Warn(warningMessage, new object());

   31             }

   32 

   33             return result;

   34         }

   35     }

Because of the simplicity and the generic functionality of these 35 lines of code, do I nominate this snap as code of the day…

Visual Studio SP1, MSBuild and Sitecore 5.3 are arguing

Having problems with Visual Studio 2005. While building my solution, Microsoft.Common.target, a MSBuild config-file tells me they want to delete several DLLs but isn’t allowed to do that. It seems to be a post built event. Can’t reproduce it directly on my Playground but I’ve the feeling that ist has somethign todo with the triangle ‘Web Application Project’, ‘Sitecore 5.3’ and MSBuild… Going to investigate it futher, stay tuned…