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

recursive looping and variable scope

Subject: recursive looping and variable scope
From: Brian Newman <brian.newman@xxxxxxxxxxx>
Date: Mon, 4 Jan 2010 14:39:06 -0500
 recursive looping and variable scope
I'm writing a windows service which will transform documents as long as it has
documents to transform.
This requires some sort of looping mechanism and, according to my
understanding, it's better to stay in XSL once you get in XSL rather than keep
bouncing back and forth between imperative and declarative code.
So, I want to do the looping inside XSL.
Therefore, I have a named template which recursively calls itself and all my
document() functions are wrapped in saxon:discard-document().
So, in link1, I'm making a call to a database to get the next scheduled
document.
In link2, I'm applying a transform on that document of all relevant data in
that document.
In link3, I'm applying any necessary outside data (data which largely comes
from the database).
Then I call result-document and output the results.

This works fine when I'm not looping.  But when I recursively call the same
named template and start over, the $filename variable isn't resetting.
Instead, I get an error "Cannot write more than one result document to the
same URI".  My guess is that I'm having trouble with the scope of $filename,
inheriting it's value from an earlier iteration of the template and, since
variables can't be reset, the new value sent to it is ignored.  Is that true?
and how do I get it to change?


<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:include href="link1.xsl"/>
	<xsl:include href="link2.xsl"/>
	<xsl:include href="link3.xsl"/>
	<xsl:template match="/">
	<xsl:call-template name="Chain"/>
	</xsl:template>
	<xsl:template name="Chain">
		<xsl:variable name="link1">
			<xsl:call-template name="getSchedule"/>
		</xsl:variable>
		<xsl:variable name="link2">
			<xsl:apply-templates mode="link2" select="$link1/jobs/job"/>
		</xsl:variable>
		<xsl:variable name="link3">
			<xsl:apply-templates mode="link3" select="$link2/policies"/>
		</xsl:variable>
		<xsl:variable name="filename">policy_<xsl:value-of
select="$link1/jobs/job/@jobid"/><xsl:text>.xml</xsl:text></xsl:variable>
		<xsl:result-document href="status.xml">
				<xsl:copy-of select="$link3/node()"/>
		</xsl:result-document>
		<xsl:call-template name="Chain"/>
	</xsl:template>
	<xsl:template match="node()"/>
</xsl:stylesheet>

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.