|
Blog archive
Knowledge and information
Technical development
Project management
Programming
Documentation
Methodology
Standards
Web browsers
General
Work and technology
Ego ergo sum
About this site
Popular links
|
Mon, 11 October 2004 13:00:00 GMT
Notice! The blog (but not the website as such) has moved slightly, and the new spot to point your feedreaders and blurry eyes to are http://shelter.nu/blog/, and I've chucked my RSS/Atom feed into FeedBurner for good measure as well. This also means no more comments here, and especially not you spammers, you filthy floatsam of the internet! Don't worry, as soon as I get some spare time I'll merge the two blogs together, just need to work out some Blog API with Blogger, or, worse, install WordPress and do it myself. We'll see what I come up with. 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; <item> Hooblas! </item> 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; <value-of select="item" /> 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; <template match="text()"></template> That's right; no text output. If we change our before given <value-of> rule to; <value-of select="item/text()" /> 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; <template match="text()"></template> 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 |


