Popular links

Topic maps

xSiteable

Claudio Monteverdi

Alexander Johannesen

Technologies used
topic map logo
xSiteable logo
Mon, 11 October 2004 13:00:00 GMT

Notice! This blog is no longer updated as such, and the new spot to point your feedreaders and blurry eyes are https://shelter.nu/blog/

This also means no more comments here, and especially not you spammers, you filthy floatsam of the internet!

XSLT at the core; tip of the day

Back from a weeks holiday, I've decided to throw together a post which summarises some interesting but essential things about XSLT. That one will have to come a bit later, but there is space for a little something right now. I held a four day course a few weeks back, and from that I noted down what people struggled with the most, and the winner is;

The difference between an element and a node

It seems I keep coming back to this. People think in elements - because we're visual people who all read XML - when in fact the world of XSLT thinks in nodes. But what, then, is a node, if not an element? Well, it's an element, too. :) Ok, let's look at some XML;

Hooblas!

When this XML gets passed through and processed by the XSLT processor, it does not mean we've got an element node with some property or something with the text in it. It all becomes nodes;

node : element : "item"

node : element : "item" : text : " Hooblas! "

node : element : "item" : attributes : none

Both text and attributes (and a few others) become sub-nodes of the "item" element node, and they may or may not be empty. In our example, there is something in our text node, but nothing in our attributes node. That means that the following XSLT code;

does not mean that it selects "what's in the 'item' element" just because there will be that text in the output. Here, again as so often happens, the built-in (and hence, hidden from the aspiring XSLT sycophant) template rules kick in and selects sub-nodes, and tries to match on those, and since the built-in match for just text kicks in, people are lead astray thinking "selecting 'item' is selecting that text inside it". Not so. Try this rule somewhere in your template, and see what happens;

That's right; no text output. If we change our before given rule to;

and it magically appears again, simply because this time, we selected the sub-node of 'item' called 'text', and displayed the value of that. So, the tip of the day is; turn off built-in rules until you understand them by doing;

It just might save the day. The next tip will be about avoiding adressing the root node. Fun, fun, fun.

Permalink (Mon, 11 October 2004 13:00:00 GMT)| Comments (0) | Programming