[vox-tech] XSLT questions

Jonathan McPherson vox-tech@lists.lugod.org
Tue, 16 Dec 2003 13:46:50 -0800


Micah,

> That would not make valid XHTML (assuming you're generating XHTML
> 1.). Your <xsl:stylesheet> opening tag should contain something like:
>
>   xmlns="http://www.w3.org/1999/xhtml"

It was, in fact, the XHTML validator that made me realize that I had a
problem in the first place.  I had the xmlns string in the stylesheet
earlier, but had removed it for some reason.  I put it back and, like
magic, I have validating XHTML code.  Thanks!

> Some processors provide extensions to convert a result fragment into a
> node set; but you should be able to do the same thing in another way
> (XSLT is Turing complete, after all). You haven't really given much
> information on what it is you want to achieve: can you give an example
> of what you're trying to accomplish?

Well, it isn't a case in which I can't get the result that I want--it's a
case of not being able to do things in the way I want to, so the fact
that XHTML is Turing-complete does not guarantee anything.

Let's say, for instance, that have an XML tag for a project
description...
here's a very contrived example:

<project name="TTP">
The TTP Project is the only project in our company with a fully
recursive acronym.
</project>

And I want to convert that to the following XHTML:

<hr />
<img class="sep" src="pretty.png" alt="" />
<hr />
<p><strong>Project name: TTP</strong></p>
<q>The TTP Project is the only project in our company with a fully
   recursive acronym.</p>

This is fine, but suppose that I soon realize that the "sep" image
surrounded by two <hr /> tags is something I use in many places in my
stylesheet, and I want to make it a parameterized entity that I can use
in many settings, like <sepimage src="pretty.png" />.  I don't know how
to do this in XSLT; it seems that I am doomed to repeat the XHTML in each
case, since <sepimage ... /> is not part of the source document.  Suppose
I change my mind and want all these separator images (both those
separating project descriptions and otherwise) to have one <hr /> rather
than two--I'll have to go through my stylesheet and find each place where
I used a separator image and fix it.

Basically, I want subroutines that I can use to abstract common but
parametric elements of my stylesheets, and after going through a number
of XSLT tutorials, I still can't find 'em.

Thanks for your help!  Much appreciated.

Jonathan.