RE: [xsl] Is it possible to modify the source-tree?

Subject: RE: [xsl] Is it possible to modify the source-tree?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 13 Sep 2005 15:30:00 +0100
The general approach to writing a multiphase transformation in one
stylesheet is

<xsl:variable name="v1">
  <xsl:apply-templates select="/" mode="phase1"/>
</xsl:variable>

<xsl:variable name="v2">
  <xsl:apply-templates select="xx:node-set($v1)" mode="phase2"/>
</xsl:variable> 

<xsl:variable name="v3">
  <xsl:apply-templates select="xx:node-set($v2)" mode="phase3"/>
</xsl:variable>

<xsl:template match="/">
  <xsl:apply-templates select="xx:node-set($v3)" mode="phase4"/>
</xsl:template>

In 2.0 you don't need the calls on xx:node-set().

So you give these preprocessing templates a mode of "phase1" and invoke the
processing as in the example above.

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

> -----Original Message-----
> From: Agnisys Technology (P) Ltd. [mailto:agnisys@xxxxxxxxx] 
> Sent: 13 September 2005 14:57
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Is it possible to modify the source-tree?
> 
> Hi Michael,
>   Could you please explain how to have the results of all the 
> templates you provided go into a
> variable? And be passed to a template like the one below ...
> 
> <xsl:template match="reg">
>   <br/>Register = <xsl:value-of select="."/>
>   Parent Offset = <xsl:value-of select="../@offset"/>
>   Sibling count = <xsl:value-of 
> select="count(preceding-sibling::reg)"/>
> </xsl:template>
> 
> Appreciating your help.
> Anupam.
> 
> 
> --- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> 
> > Start with an identity template:
> > 
> > <xsl:template match="*">
> >   <xsl:copy>
> >   <xsl:copy-of select="@*"/>
> >   <xsl:apply-templates/>
> >   </xsl:copy>
> > </xsl:template>
> > 
> > Add a template to handle the href:
> > 
> > <xsl:template match="reg[@href]">
> >   <xsl:copy-of select="//regdef[@name=current()/@href]"/>
> > </xsl:template>
> > 
> > And another template to avoid copying the regdef:
> > 
> > <xsl:template match="regdef"/>
> > 
> > This creates the document that you say you want to form the 
> *input* to the
> > transformation. So you want a pipeline of two 
> transformations: first the one
> > above, then the other one you had in mind. You can either 
> write the two
> > transformations as part of the same stylesheet (using 
> modes, with a variable
> > used to hold the result of the first transformation) or you 
> can put them in
> > separate stylesheets and organise the pipeline at the 
> application level.
> > 
> > Michael Kay
> > http://www.saxonica.com/ 
> > 
> > > -----Original Message-----
> > > From: Agnisys Technology (P) Ltd. [mailto:agnisys@xxxxxxxxx] 
> > > Sent: 13 September 2005 00:03
> > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > > Subject: RE: [xsl] Is it possible to modify the source-tree?
> > > 
> > > My input looks like this:
> > > <a>
> > >    <b offset="5">
> > >       <reg>reg_1</reg>
> > >       <reg href="REGDEF1"/>
> > >    </b>
> > > 
> > >   <regdef name="REGDEF1">
> > >       <reg>reg_10</reg>
> > >       <reg>reg_20</reg>
> > >   </regdef>
> > >  
> > > </a>
> > > 
> > > I want the <reg href="REGDEF1"/> be replaced with the 
> > > definition defined above, namely :
> > >       <reg>reg_10</reg>
> > >       <reg>reg_20</reg>
> > > 
> > > So to the XSLT parser, the input looks like:
> > > <a>
> > >    <b offset="5">
> > >       <reg>reg_1</reg>
> > >       <reg>reg_10</reg>
> > >       <reg>reg_20</reg>
> > >    </b>
> > > </a>
> > > 
> > > The output is based on the attributes of the <b> node and the 
> > > siblings. If I use
> > > <xsl:apply_templates> I will have to pass a whole bunch of 
> > > info to the template.
> > > 
> > > Thanks,
> > > Anupam.
> > > 
> > > 
> > > --- Michael Kay <mike@xxxxxxxxxxxx> wrote:
> > > 
> > > > The simple answer is: no.
> > > > 
> > > > You'll have to explain the requirement more carefully, I 
> > > can't really
> > > > understand from this what you're trying to do.
> > > > 
> > > > Michael Kay
> > > > http://www.saxonica.com/ 
> > > > 
> > > >
> > > 
> > > 
> > > 		
> > > __________________________________ 
> > > Yahoo! Mail - PC Magazine Editors' Choice 2005 
> > > http://mail.yahoo.com
> > 
> > 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 

Current Thread