xsl-list
[Top] [All Lists]

RE: Applying a transform to a tranform

2003-09-09 15:43:59

I have a situation where I would like apply a transform to 
the transform of an xml document.  Is there a way to do this 
in one xslt document?

Yes, if your processor offers the node-set extension. The pattern is:

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

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

(Of course either phase1 or phase2 can be replaced with the default
mode, or you can even run both phases in the same mode, but this needs
care.)

Michael Kay


For example the original xml looks like

<rowset>
  <row>
    <id>1</id>
    <value>value 1</value>
    <parent>0</parent>
  </row>
  <row>
    <id>2</id>
    <value>value 2</value>
    <parent>1</parent>
  </row>
  <row>
    <id>3</id>
    <value>value 3</value>
    <parent>0</parent>
  </row>
</rowset>

The first transform (which I have written and works) results in:

<tree>
  <branch>
     <id>1</id>
     <value>value 1</value>
     <branch>
        <id>2</id>
        <value>value 2</value>
     </branch>
  </branch>
  <branch>
    <id>3</id>
    <value>value3</value>
  </branch>
</tree>

Now in the same xslt document I would like to transform this 
into the html code to represent a "tree" control.  I have 
written the transform document to do this and it works when 
supplied with an xml document of the "tree/branch" type.  The 
problem I am having is making the first transform happen on 
the original document and then the second transform on the 
first transform results.

I thought the following logic would work but it doesn't

<xsl:apply-templates select="rowset"/>  -- to transform into 
tree like xml <xsl:apply-templates select="tree"/> -- to 
transform into html tree control

It appears as though this is transforming the original doc in 
both instances (i.e. the rowset template select doesn't 
"pass" the results of its transform forward).

Is it possible to make the second transform use the results 
of the first in the same doc?? Thanks in advance!






 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>