|
next
|
 Subject: multi-phase XSLT 2.0 transformation Author: Tim Crews Date: 02 Aug 2007 06:57 PM
|
Hello:
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):
<xsl:variable name="phase-1-output">
<xsl:apply-templates mode="phase-1"/>
</xsl:variable>
<xsl:result-document>
<xsl:apply-templates select="$phase-1-output" mode="phase-2"/>
</xsl:result-document>
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
mode="phase-2"
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.
I've tried:
<xsl:template select="/" mode="phase1">
<xsl:copy-of select="*"/>
</xsl: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?
Thank you for your time.
|
|
|
|