[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Applying a transform to a tranform

Subject: Re: Applying a transform to a tranform
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 09 Sep 2003 18:58:26 -0400
xsl tranform
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@xxxxxxxxxxxxxxxx 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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.