Re: [xsl] Newbie ? - dynamic linking two xslt templates

Subject: Re: [xsl] Newbie ? - dynamic linking two xslt templates
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 21 Sep 2006 09:13:49 +0200
Hi Jeremy,

please see my comments,

Cheers,
Abel Braaksma
http://abelleba.metacarpus.com

Jeremy Patterson wrote:
I believe xslt/xml solution is still the best way to do this. I have come up with two xslt templates, one listing all the teachers(teacher directory), and another that generates the teacher's webpage based on a variable that is passed into xslt template. The teacher directory webpage will trigger the teacher xslt and pass a teacher's name, thus creating the teacher webpage. They are both generated from the same xml document, that will be updated by a web form (it's not their yet).

This sounds like a server-side approach to me. Which is good, because you can do more and you'll have less trouble dealing with browser peculiarities.

The problem I have is generating the dynamic link that will trigger the teacher xslt template. I have very limited experience with xml/xslt, I have always embedded the xslt page in the xml document like this:
<?xml-stylesheet type="text/xsl" href="xslTemplate.xsl"?>

This means you actually use a client-side approach. It is possible, but I would advice against it. And even if you do, I'd advice to make it a little more sophisticated: select the XML file through Javascript's XMLHttpRequest object (this is AJAX technology, there're books written about it and mailing lists also) and parse it client side using and XSLT engine from the client. After that, you can server it however you like. And you have the option to choose your stylesheet, your XML and your parameters. But this is not an *easy* solution. In fact, it requires quite some knowledge of a multitude of technologies.

I don't think this is going to work because I'm using two different xslt templates. I also have no idea on how I would write the link to the teacher template, I would imagine the link would be the same, but I would just be passing a different value to the parameter in the teacher xslt. I have always just linked to the xml page which would trigger the xslt, but I don't think I can do that because I have two xslt templates working off the xml document.

There are so many options to fill this one in. Do you need to do it all on the client side, or can you parse/transform on the server side? That would end up being so much easier.

This has to be a simple solution. I'm using Jenni Tennison's "Beginning XSLT 2.0" for reference. It has helped immensely in suggesting I compile through saxon, so I can view output. I'm hung up on creating the dynamic links that will link the two xslt templates together.

Good! But remember, you are doing client side xslt, this is only XSLT 1.0. Browsers as of yet are not capable of anything more than that and won't be for some time to come.


Conclusion: you'll have to choose some technique, client side transformation or server side transformation. In the latter case, you can use Saxon's XSLT 2.0 capabilities (if you stick to saxon on the server side, but there are more engines to choose from). In the former case, be prepared to spend some time learning the various techniques involved.

You may even choose to do it with a little bit of server effort and the rest the way you do it now: client side. One (of many) approach can be, making the following statement in the XSLT file dynamic using SSI, or a server language like PHP, Perl etc.
<?xml-stylesheet type="text/xsl" href="{{{fillthisindynamically}}}"?>


Current Thread