[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] multiple transformations (pipelining) in one stylesheet


Subject: RE: [xsl] multiple transformations (pipelining) in one stylesheet
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 19 Oct 2007 18:19:19 +0100

> I tried to adapt your model (used your mode names to see if I 
> understand it) but there must be an error, I don't get any output.
> 
> <xsl:stylesheet version="2.0" 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>   <xsl:output method="xml" encoding="UTF-8" 
> omit-xml-declaration="yes"/>
> 
>   <xsl:template match="@*|node()" mode="phase-1">
>     <xsl:copy>
>       <xsl:apply-templates select="@*|node()"/>

You need to use mode="phase-1" here (or mode="#current")

>     </xsl:copy>
>   </xsl:template>
> 
>   <xsl:template match="acronym" mode="phase-1">
>     <xsl:value-of select="@text"/>
>   </xsl:template>
> 
>   <xsl:template match="/" mode="phase-2">
>     <p>
>       <xsl:value-of select="/file/content/para"/>
>     </p>
>   </xsl:template>
> 
>   <xsl:variable name="phase-1-output">
>     <xsl:apply-templates select="/" mode="phase-1"/>
>   </xsl:variable>
> 
>   <xsl:variable name="phase-2-output">
>     <xsl:apply-templates select="$phase-1-output" mode="phase-2"/>
>   </xsl:variable>
> 
>   <xsl:template match="/">
>     <xsl:apply-templates select="$phase-2-output" mode="phase-3"/>
>   </xsl:template>
> 
> </xsl:stylesheet>
> 
> So it works like this:
> 1) template (match="/") pulls in result from $phase-2-output
> 2) $phase-2-output is build by applying phase-2 templates to 
> $phase-1-output
> 3) $phase-1-output is build by applying phase-1 templates to 
> root of document
> 
> Am I right?
> 

Yes, that's the idea.

Note, the variables can either be global, or they can be local variables
within the match="/" template.

Michael Kay
http://www.saxonica.com/


Current Thread