Re: [xsl] re: recursive looping and variable scope

Subject: Re: [xsl] re: recursive looping and variable scope
From: Mukul Gandhi <gandhi.mukul@xxxxxxxxx>
Date: Thu, 7 Jan 2010 08:45:45 +0530
I don't think, that a recursive template should be an issue, for the
error that XSLT processor is reporting, "for attempting to write to
the same URI". This should work fine, as long as URIs are different in
each recursive call.

The URI is generated with this code fragment:
<xsl:variable name="filename">policy_<xsl:value-of
select="$link1/jobs/job/@jobid"/><xsl:text>.xml</xsl:text></xsl:variable>

and this is dependent on variable, $link1 which is populated by
execution of the template, "getSchedule".

I suspect, there could be an issue with logic inside template,
"getSchedule" (which you haven't shared with us. can you please show
that if it's possible.) which is probably generating similar content
in different template calls.


On Thu, Jan 7, 2010 at 5:37 AM, Brian Newman <brian.newman@xxxxxxxxxxx>
wrote:
> The code I meant to show is below
> <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";>
> B  B  B  B <xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>
> B  B  B  B <xsl:include href="link1.xsl"/>
> B  B  B  B <xsl:include href="link2.xsl"/>
> B  B  B  B <xsl:include href="link3.xsl"/>
> B  B  B  B <xsl:template match="/">
> B  B  B  B <xsl:call-template name="Chain"/>
> B  B  B  B </xsl:template>
> B  B  B  B <xsl:template name="Chain">
> B  B  B  B  B  B  B  B <xsl:variable name="link1">
> B  B  B  B  B  B  B  B  B  B  B  B <xsl:call-template name="getSchedule"/>
> B  B  B  B  B  B  B  B </xsl:variable>
> B  B  B  B  B  B  B  B <xsl:variable name="link2">
> B  B  B  B  B  B  B  B  B  B  B  B <xsl:apply-templates mode="link2"
select="$link1/jobs/job"/>
> B  B  B  B  B  B  B  B </xsl:variable>
> B  B  B  B  B  B  B  B <xsl:variable name="link3">
> B  B  B  B  B  B  B  B  B  B  B  B <xsl:apply-templates mode="link3"
select="$link2/policies"/>
> B  B  B  B  B  B  B  B </xsl:variable>
> B  B  B  B  B  B  B  B <xsl:variable name="filename">policy_<xsl:value-of
select="$link1/jobs/job/@jobid"/><xsl:text>.xml</xsl:text></xsl:variable>
> B  B  B  B  B  B  B  B <xsl:result-document href="{$filename}">
> B  B  B  B  B  B  B  B  B  B  B  B  B  B  B  B <xsl:copy-of
select="$link3/node()"/>
> B  B  B  B  B  B  B  B </xsl:result-document>
> B  B  B  B  B  B  B  B <xsl:call-template name="Chain"/>
> B  B  B  B </xsl:template>
> B  B  B  B <xsl:template match="node()"/>
> </xsl:stylesheet>
>
> As I mentioned earlier, I'm getting an error indicating that I can't write
multiple files to the same URI. B I'm using Saxon and have all my document()
calls wrapped in saxon:discard-document.
> $filename doesn't appear to be resetting it's value when I loop. B I'm not
sure why.
> Another question, is it generally a good idea to loop like this in Saxon?
B I assume Saxon will release its resources when they go out of scope -
especially with the saxon:discard-document function, but this loop is designed
to run an indeterminate period of time - theoretically forever.
>
> Again, I appreciate the help you've all offered in helping a guy get up to
speed on Saxon and XSLT2.
> Hopefully, I can, one day, return the favor by helping someone else out.



--
Regards,
Mukul Gandhi

Current Thread