[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|