Sjoerd Visscher's weblog
Last Update
10/16/2005; 1:25:22 AM
Thursday, January 30, 2003
XInclude support
I'm now reaping the benefits of having an xml weblog. I wanted referrers on each page. But Radio generates static pages, and only the server knows the referrers. I now include the referrers using XInclude:
<xi:include href="/tools/refs.php?url=url" xmlns:xi="http://www.w3.org/2001/XInclude" />
The task of implementing something like this seems a lot of work at first, but it was rather easy. Thanks to the document() function from XSL:
<xsl:template match="xi:include"> <xsl:apply-templates select="document(@href)" /> </xsl:template>
Tuesday, January 28, 2003
Dynamically extending APIs
Usually when a cool Python script comes along, I'm thinking if Javascript can do this too. It almost always can. Yet there are so few Javascript fans that I can't help but showing what Javascript can do to anybody that will listen.
Today Mark Pilgrim shows how to dynamically extend APIs with Python. Javascript can do this too, it's almost trivial even. At Q42 we use this a lot in Mozilla to extend the DOM with some of the more useful Internet Explorer features. (We would like to be able to do this the other way around, but IE's DOM is not implemented in a very Javascript compatible way.) Here's one example how to extend the DOM to support the selectSingleNode method. Note that after the code has executed, all XML and HTML nodes support the method.
Node.prototype.selectSingleNode = function(xpath)
{
var xpe = new XPathEvaluator();
return xpe.evaluate(xpath, this, xpe.createNSResolver(this),
XPathResult.FIRST_ORDERED_NODE_TYPE, null);
};
Sunday, January 26, 2003
XHTML 2 on the Mac
The first Mac fan to mail was Mark Pilgrim. The result for the Mac browsers: zero out of four. There were two different problems. OmniWeb and MSIE 5 give 100% width to absolute positioned elements. This was quickly fixed with some CSS. The problem with Chimera and Safari was that they have "Gecko" in the User Agent string. But they both don't support XSLT. So I had to make exceptions for them. And Mark confirmed that this weblog now looks acceptable in all 4 Mac browsers. Yay!
In the mean time XHTML 2 hasn't let me down. If it turns out that the client side transformations don't work, I'll stick to XHTML2, and just transform it on the server for all browsers. I've started on implementing XML Events. It's already working in IE. I like the syntax. An onclick attribute in HTML becomes a script child element in XML Events, with an ev:event="click" attribute.
Saturday, January 25, 2003
Conditional server side transformations
If you do not have Internet Explorer 6 or a Gecko based browser, you should be able to read this site again. The transformation of XHTML 2, which IE6 and Mozilla can do themselves, is now done on the server. Inspired by Mark Pilgrim I did this using mod_rewrite.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "!MSIE 6"
RewriteCond %{HTTP_USER_AGENT} !Gecko
RewriteCond %{REQUEST_URI} !rss.xml$
RewriteRule ^/(.*).xml$ /tools/x.pl?$1 [L]
This means that a url like /weblog/2003/01/25.xml is rewritten as /tools/x.pl?weblog/2003/01/25. x.pl is a small perl script (my first perl script actually) that transforms the xhtml 2 file to html 4.01. I hope this site now displays properly on most browsers, unless it can't handle the CSS. I don't have a Mac to test it on, but I'm sure I'll get a report from a Mac fan ;).
Thursday, January 16, 2003
Bug #1
Dave is linking to me, but that didn't show up in the stats. Maybe that is fixed with this update. (It's not clean XHTML 2, but I have to have my stats!)
Switched to XHTML 2.0
OK, if Mark is going back to HTML 4, then I'm going forward to XHTML 2.0. I don't care it means that about 10 to 15 percent of my visitors will see garbage. Maybe I'll add a fallback trick later.
You see, XHTML 2.0 is not the format for the next generation browsers. It has nothing to do with browsers. XHTML is an XML Hypertext Markup Language. Browsers can do much more than displaying (X)HTML, and their behaviour is defined using CSS, and HTC or XBL. The browser needs to recognize links so they can be bookmarked, and recognize a title for the titlebar of the window. It is very inconvenient that these functions are tied to HTML elements, and a hiatus in the W3C specs.
XHTML, and specifically version 2.0, is a perfect dataformat for weblogs. And ever since I made my first XHTML 2.0 page, its clean markup was begging to be used on the whole site. So I made the switch. I changed the templates to let Radio spit out nice XHTML 2.0 documents for me, and the default file on this server is now index.xml. Things will probably get buggy for some weeks. It'll be interesting to see how this turns out.