XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Tim CrewsSubject: 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.

Postnext
Tim CrewsSubject: multi-phase XSLT 2.0 transformation
Author: Tim Crews
Date: 02 Aug 2007 11:24 PM
I am trying to break this problem down into smaller sub-problems.

So, the first sub-problem is, how do I get things started in a new mode?

For example, what if I have the identity transform defined, but in phase-1 mode, e.g.:

<xsl:template match="node() | @*" mode="phase-1>
<xsl:copy>
<xsl:apply-templates select="@* | node()" mode="phase-1"/>
</xsl:copy>
</xsl:template>

How do I kick off this identity transform in mode "phase-1"?

I have tried adding a top-level template matching "/", e.g.:

<xsl:template match="/">
<xsl:apply-templates "*" mode="phase-1"/>
</xsl:template>

But this doesn't work.

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.

Posttop
Tim CrewsSubject: multi-phase XSLT 2.0 transformation
Author: Tim Crews
Date: 03 Aug 2007 01:02 AM
The solution to the kick-off problem is simply

<xsl:template match="/">
<xsl:apply-templates mode="phase-1"/>
</xsl:template>

As a cautionary note, at one time I had declared xsl as the default namespace for my stylesheet, so that I could type

<template match="/">
<apply-templates mode="phase-1"/>
</template>

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.

Thanks for following along.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.