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

Re: Calling a template before any other templates

Subject: Re: Calling a template before any other templates
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 11 Apr 2012 13:37:20 -0400
Re:  Calling a template before any other templates
At 2012-04-11 13:29 -0400, Peter Desjardins wrote:
Hi. I am trying to do something in XSLT 2.0 that requires that some of
my templates know what the result of other templates is (or will be).
I want to run a process that writes a file before any other templates
run and then be able to refer to that file during the rest of the
processing.

That requires multiple invocations of the processor.


In XSLT 2.0 you can, however, put the results of a template into a variable and then work with the variable.

If I call a template from the first template like the following, can I
rely on it being completed before any other templates are applied? Is
there a reliable way to perform an operation before any templates are
applied?

I'm unclear why you are saying "before". If the template is writing a file, that file cannot be read subsequently regardless.


But, because your called template is being called before the other template rules fire, you can be assured that any building of the result tree is done before.

<xsl:template match="/">
  <xsl:call-template name="this.template.must.be.first" />
  <xsl:apply-templates/>
</xsl:template>

You can do the following in order to put the first template into a structure you can then access later as a parameter:


  <xsl:template match="/">
    <xsl:apply-templates>
      <xsl:with-param name="myStuff" tunnel="yes">
        <xsl:call-template name="blah"/>
      </xsl:with-param>
    </xsl:apply-templates>
  </xsl:template>

Then, in your match of any construct you can have:

  <xsl:template match="x">
    <xsl:param name="myStuff" tunnel="yes"/>

    .... $myStuff/y/z ....
  </xsl:template>

Alternatively, you can simply process the template into a global variable and then access the global variable. Regardless of how many times you access the global variable, it will only be evaluated once.

But you cannot, in either XSLT 1.0 or XSLT 2.0, create a result tree as an output file and then access that output file in the same invocation of the processor.

I hope this helps.

. . . . . . . . . Ken


-- Public XSLT, XSL-FO, UBL and code list classes in Europe -- May 2012 Contact us for world-wide XML consulting and instructor-led training Free 5-hour lecture: http://www.CraneSoftwrights.com/links/udemy.htm Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal

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.