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.

3 thoughts on “Sitecore XSLT guide for beginners – Part 1 – Terminology”

  1. i’m an XSLT allergic by heart :), but i can’t help but agree with you on many of your points here.

    it terms of efficiency and ease of use it’s really good, but quality, in my personal opinion, really requires a skilled xsl developer..

    but i’ll say it, even tho i’m not a personal fan of xsl/xslt/xsl:fo it really is a very good way to bring structure, quality and speed to ones delivery process.

    good article, looking forward to more 🙂

    P.

  2. I as well as my pals ended up taking note of the good guidelines found on your web site and so quickly developed a terrible feeling I never expressed respect to the website owner for those strategies. All of the boys ended up for that reason happy to read them and have in effect in reality been having fun with those things. We appreciate you really being quite helpful and also for deciding upon such essential areas millions of individuals are really desperate to be informed on. My very own honest regret for not saying thanks to sooner.

  3. At this moment I am going to do my breakfast,
    afterward having my breakfast coming over again to read further news.

Comments are closed.