Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old May 7th, 2005, 02:52 PM
Registered User
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiphase processing

I would like to process a document in phases, and expect I need to use modes, but can't put it all together. I have a global stylesheet in one file, and a local one in another. The local one is supposed to transform some of the tags into ones that are understood by the global one, then the global one is supposed to transform those into the final output result. If we call these type L tags and type G tags, then I want all the L tags transformed into G tags and text. The L tags and the G tags are all intermingled in the source document. The L tags typically are quite simple. For example, an L tag might be <q/>, which should get transformed in the first phase into the G tag and content <sym>q</sym>. which then should be transformed along with all the rest of the G tags into the output document (in OO writer XML). The idea is for every source document to have its own peculiar set of tags in the local stylesheet, in addition to the general ones in the global stylesheet. My problem is how to build an intermediate document that retains the global markup while transforming local markup into global, then to apply the second set of transformations to the intermediate document. A simple example I could run would be greatly appreciated.

  #2 (permalink)  
Old May 7th, 2005, 04:38 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts

There are basically two ways of doing a multiphase transformation: the single stylesheet approach and the multiple stylesheet approach. For big applications, writing one stylesheet per phase has many benefits - it keeps the code simpler, and makes it more reusable; the downside is that you need some extra machinery (e.g. a pipeline processor such as Orbeon) to manage the pipeline.

The single stylesheet approach, which you are attempting, takes the general form:

<xsl:variable name="phase-1-output">
 <xsl:apply-templates mode="phase-1"/>

<xsl:variable name="phase-2-output">
 <xsl:apply-templates select="xx:node-set($phase-1-output)" mode="phase-2"/>

<xsl:template match="/">
  <xsl:apply-templates select="xx:node-set($phase-2-output)" mode="phase-3"/>

With an XSLT 2.0 processor the call on xx:node-set() is no longer needed.

Without seeing your code I can't see where you are getting stuck but hope this coding pattern will help you.

Michael Kay
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
  #3 (permalink)  
Old May 7th, 2005, 05:57 PM
Registered User
Join Date: May 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts

Hi Michael,

I have really enjoyed your XSLT book. I have the first and second editions. It is extremely lucid and well-organized, which is especially tough to achieve given the complexity of the subject matter. Thanks for taking the time to reply to me. My problem is that I only seem to need XSLT every couple of years, and I forget everything I learned in the meantime.

I have reduced the problem to the two simple files below, a source XML document and and the global stylesheet. Within the source document, you will notice that I have two variables, x and y. The global stylesheet knows how to process the tags I used for x, but not the <y/> tag. To avoid having to put <sym>y</sym> every time I want to refer to y, I want a second local stylesheet that will first change <y/> into <sym>y</sym>, while leaving the other tags intact. In the second phase, the global stylesheet will then only be presented with tags it knows how to handle. My thought is that each such local stylesheet (which corresponds to a project) will simply include the global one.

I hope this is specific enough now so that someone might show me how to do the local stylesheet using the modes approach and my global stylesheet.

(Since my earlier posting I found an identity stylesheet in Roger Costello's tutorial decks that I think I can modify to do the local transform, achieving the desired result in two separate transformations, as you suggested.)


-- source XML document -------------------------
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="jce.xsl"?>
    <t>My Title</t>
    <par>Let <sym>x</sym> be the length of the table and
    <y/> be its width.</par>

--- global transform stylesheet ----------------------
<?xml version="1.0"?>
    <xsl:output method="xml" encoding="UTF-8" indent="yes" />
    <xsl:template match="/">
        <xsl:apply-templates />
    <xsl:template match="t">
        <title><xsl:apply-templates /></title>
    <xsl:template match="sym">
        <em><xsl:apply-templates /></em>
    <xsl:template match="par">
        <p><xsl:apply-templates /></p>


Similar Threads
Thread Thread Starter Forum Replies Last Post
Node Processing adamflynn XSLT 6 September 7th, 2006 05:42 AM
For-Each processing problem MargateFan XSLT 2 May 11th, 2006 11:39 AM
Processing String Little Shell VB.NET 2002/2003 Basics 2 June 2nd, 2005 06:07 PM
image processing ck Visual C++ 0 February 27th, 2005 03:31 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.