xsl-list
[Top] [All Lists]

Re: Applying a transform to a tranform

2003-09-09 15:58:26
Hi Todd,

It is possible in XSLT 1.0 only if you use your vendor's node-set() extension, which is designed specifically for this purpose. Most processors have this extension function available in some form: check your documentation. In particular, you might look into whether yours supports functions in the EXSLT namespace ("Extended XSLT", an effort of several well-regarded members of our community, see http://exslt.org), which is even a semi-portable version.

In XSLT 2.0 the conversion of result-tree-fragment to node-set, which is what this function does, is transparent: you won't even have to think about it.

To do what you want to do using the EXSLT version:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
    xmlns:exslt="http://exslt.org/common";
    extension-element-prefixes="exslt">

<xsl:variable name="first-process-results">
  <!-- you'll want either an explicit path here, or better, a
       mode, to avoid infinite recursion -->
  <xsl:apply-templates select="/rowset" mode="first"/>
</xsl:variable>

... then your normal templates in the mode "first" ...

And then your actual transform:

<xsl:template match="/">
  <xsl:apply-templates select="exslt:node-set($first-process-results)"
    mode="second"/>
</xsl:template>

... and your second-pass templates in the mode "second"....

Basically what this is doing is processing the document in one mode, binding the result to a variable (in XSLT 1.0 it's a "result tree fragment"), then the stylesheet processes this fragment, turning it into a node set using the extension function.

You don't have to use modes, but you might be sorry if you try it without. :->

At 05:04 PM 9/9/2003, you wrote:
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

In the context where you invoke these, the second apply-templates has no way to know you don't mean "child::tree" (XPath "tree" = XPath "child::tree"), but rather the results of the first apply-templates. It's only doing what you're telling it to (processing the tree children of the context node).

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).

No, and it'd be pretty bizarre if it did, without your even asking. (Where would it all end? :-> )

Anyhow, try a node-set() function and see how it works.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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



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