Thursday, January 16, 2003
Alphabet Soup of the Viet-Cong
I started to convert my website to XML back in October but what with the holiday season and what not, that particular project got pushed back. But the past week or so I've resurrected that particular project and I've been immersed in XML, XSLT, HTML and CSS and other alphabet soups of technology.
I had started with converting my humor columns over to XML (of which I had converted about half) and wrote an XSLT file to convert them to XHTML. Earlier this week, I picked up where I resumed, converting the rest to XML and tweaking the templates. Given the recent brouhaha over XHTML, plus an inability of some older browsers to properly handle the XHTML markup, I rethought the notion of using XHTML and went back to HTML 4 strict (which is now an easy thing to do given I'm using templates).
I had started with one of the lower sections of my website and was working my way up (I had finished with Murphy's Law, now time to work on the High-Brow Literary Section) when I started having integration problems, mainly with XSLT. I was working on one template file for the writing section, and I already had a separate template file for the columns.
<?xml version="1.0" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:include href="murphy/murphy.xsl"/>
writings.xsl
When I wasn't getting errors I was getting odd results. Perhaps it was
still my unfamiliarity with XSLT and the differences between
<xsl:include>
and <xsl:import>
but I
was having a difficult trying to locate the source of the odd results, like
spurious output when there shouldn't have been any.
I then switched to a top-down conversion, with a single XSLT file. I rewrote what I had, making naming changes to clarify what template what was and what was going on.
Whatever I did, it cleared up the problems I was having.
It's slow going, and XSLT is not the prettiest of languages to program in (and yes, it is Turing Complete so it is a programming language) and I'm still trying to get used to XPath expressions.
<xsl:call-template name="common-meta-tags"> <xsl:with-param name="year"><xsl:value-of select="substring(@ref,1,4)"/></xsl:with-param> </xsl:call-template> <xsl:if test="position()>1"> <link type="text/html" rel="next" title="{preceding-sibling::about[position()=1]/attribute::date}" href="../{preceding-sibling::about[position()=1]/attribute::ref}.html" /> </xsl:if> <xsl:if test="position()<last()"> <link type="text/html" rel="previous" title="{following-sibling::about/attribute::date}" href="../{following-sibling::about/attribute::ref}.html" /> </xsl:if>
site.xsl
—Portion of code to
generate the index of about pages
Yes, the relational operators like <
have to be encoded as
<
since this is XML—like I said, it's not pretty. And certain
XPath expressions can use the
short form, while others (such as selecting adjacent nodes with
preceding-sibling
and following-sibling
) have to
use the fully qualified notation and you have to know when that is (of the
thirteen axis you can step by, child, descendant, descendant-or-self,
parent, ancestor, ancestor-or-self, following-sibling, preceding-sibling,
following, preceding, attribute, namespace
or self
only
five can be expressed in a shorthand notation, self
(as “.”),
parent
(as “‥”), child
(as the name of the
element), descentant-or-self
(as “/”) or
attribute
(with a “@” preceding the name of the
attribute)).
I hope you got all that (and I suspect I just lost all my readers at this point).
You also don't have variables, even though
<xsl:variable>
would lead you to think so; it's more a
named constant than a variable.
It's stuff like this that reminds me of the Vietnam draftee Kansas farm boy walking through the jungles of South East Asia oblivious to the various trip wires the Viet-Cong have planted …