xsl.
¶ by Rob FrieselMo’ XSL ish for your eye-hole. (Been a while since I blogged the geeky core of my soul out on this madness.)
Problem: Generating well-formed xml-based FAQs that are easy to read and (even!) pretty (if there is such a thing) is all well and good. But who wants to read through a whole huge FAQ for the one Q? Why spend all day browsing it when the question you want to ask should be at the very top? So you can single-click and drill down to the details?
Solution: (the theoretical..) Why not then just program the XSL to output an assigned number (or some such) to the questions and do exactly that?
The way this played out in XSL was a bit different from how I would have done it in any other language that I know. Therefore, it took twice as long to arrive at the (actually quite elegant) solution.
Given how I’ve done maybe-not-the-same-but-definitely similar things in JavaScript, Velocity, and PHP– My initial thought was to invoke a for loop or something along those lines. Something that would keep a counter, number each ques and increment the counter at the end of each line. Those numbers would get dumped into a hrefs … #hashed, of course (to keep everyone on the same page). Only problem so far is that XSL doesn’t really have for loop constructs like that. At least, none that I know of.
So my thoughts turn to xsl:variable. Examination begins and continues ad nauseum for some time. Several man hours invested here. Lots of What about this? and How about that? and I wonder if I… Potentially … nay … definitely maddening.
Then out of the freakin’ blue we (‘we’ being ‘I’) stumble across xsl:number and it’s like a bolt of miraculous lightening. We’re still invoking xsl:variable but rather than look for existing content nodes, we look at them and get our counts from there. Suddenly lots of stumbling, sickly select="." statements become:
<xsl:variable name="count">
<xsl:number count="ques" level="any" />
</xsl:variable>
Just remember to drop the {$count} in the right places and all you have to worry about is scope. Hoo-haw!! NOW… If I could just figure out why it’s dropped in as {$count} and in once place and needs to be {$count+1} in the other… Weird.
—
Oh, and I’m going to be an uncle. Wish I could say that I was happy. But I just managed to numb myself from the sickening shock of lies and deception that constituted my brother’s wedding.
Leave a Reply