Error: Circular definition of variable ...

Here should go questions about transforming XML with XSLT and FOP.
phranck
Posts: 1
Joined: Mon Jul 28, 2008 5:06 pm

Error: Circular definition of variable ...

Post by phranck »

Hi there!

In an XSL I have the following lines of code:

Code: Select all


  <xsl:variable name="hasSecondPage">
<xsl:choose>
<xsl:when test="$numberOfRounds = $numberOfRoundsToDisplayOnFirstPage and $numberOfRounds > $maxNumberOfRoundsOnFirstPage">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:when test="($numberOfRoundsToDisplayOnFirstPage < ($numberOfRounds + 1)) and ($numberOfRounds != $numberOfRoundsToDisplayOnFirstPage)">
<xsl:value-of select="true()"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="false()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<xsl:variable name="numberOfRoundsToDisplayOnFirstPage" as="xs:integer">
<xsl:variable name="rounds" select="/tourmatchesreport/tourmatchesreportitem/numberOfRoundsToDisplayOnFirstPage" as="xs:integer"/>
<xsl:choose>
<xsl:when test="$hasSecondPage = true()">
<xsl:value-of select="$rounds"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$rounds + 1"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
If I do a transformation with the related XML this error occurs:

Code: Select all


SystemID: ~/Developer/theLeague/TennisFramework/tournamentMatchesReportRaster64.xsl
Description: Circular definition of variable hasSecondPage
The confusing thing is, if I change the definition of the variable 'numberOfRoundsToDisplayOnFirstPage' to the following code, everything is fine:

Code: Select all


<xsl:variable name="numberOfRoundsToDisplayOnFirstPage" select="/tourmatchesreport/tourmatchesreportitem/numberOfRoundsToDisplayOnFirstPage" as="xs:integer" />
What is wrong here?

Thanks for your help,
phranck
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Error: Circular definition of variable ...

Post by sorin_ristache »

Hello,

The variable hasSecondPage was defined based on the variable numberOfRoundsToDisplayOnFirstPage which was defined based on hasSecondPage. This is a circular definition because the definition of hasSecondPage is based on itself. A definition in which the value of a variable is based on the value of the same variable is not allowed in XSLT.


Regards,
Sorin
Post Reply