I want to implement a multi-phase XSLT transformation using a temporary tree to pass the results of the first phase to the second phase. This technique is very briefly introduced in Michael Kay's "XSLT 2.0 Reference" on page 82, and if you google "XSLT multiphase transformation" you will see that he often snips the same example when helping people online.
Unfortunately, in all of these cases he only shows the template application, not the template definition itself.
So here's what he shows you (shortened to only use two phases; he usually demonstrates with three):
That much I understand. The part I don't know how to do is actually declare and implement the phase-1 and phase-2 templates. What should they match? What should they produce, and how?
For example, what if I had a pre-existing stylesheet that was working fine with a top-level template that matched "/", and now I just add a
attribute to that existing template declaration.
Now, just to show that I can get two phases to talk to each other, I want to create a "do-nothing" phase-1 template.
Then, if I string phase-1 and phase-2 together they way that is described earlier in this message, I would expect to get the same results that I originally got with the working stylesheet. But I don't. I get nothing.
Does anyone out there do this kind of transformation a lot? Can anyone point me to an on-line example that shows all levels of the implementation of this pattern?
I have never seen an example of the identity transform used with a non-default mode value. But if I'm going to implement a multi-phase transformation (which requires the use of a different mode for each phase), and if any of my phases rely on the identity transform (and all of my phases do), then I have to know how to do this.
But this is a bad habit. Among other things, Stylus Studio's Sense:X feature doesn't work when you do this.
A number of my problems were caused by getting rid of the default namespace, but forgetting to put "xsl:" prefixes back in my XSLT element tags.
In short, I believe I now have a working multi-phase XSLT transformation, and most of the problems that I thought existed were actually either just my imagination, or the result of stupid errors. In my defense, I've been working 15 hours a day for almost three weeks now. It makes me stupid.