J
Jody Gelowitz
I have run into an issue with variable scope within an XSLT document that is translated in VS.NET 2.0. Under VS.NET 1.1 (XslTransform), this code works fine. However, when using VS.NET 2.0 (XslCompiledTransform), the exact same XSLT transformation fails with the error:
System.Xml.Xsl.XslLoadException: The variable or parameter 'lastrecordwaskit' was duplicated within the same scope. An error occurred at (174,12).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet)
at MyProject.MyClass.TranslateXML(String xsltFileName, String xmlText) in C:\Source\MySolution\MyProject\MyClass.vb:line 155
I have included the XSL code below which is related to the issue. In order to maintain the previous value of "iskit", I am declaring a variable "lastrecordwaskit" at the end of the loop. Near the beginning of the loop, prior to the variable declaration of "lastrecordwaskit", I am checking for "position() > 1" before trying to access "lastrecordwaskit". In .NET 1.1, this would allow the "lastrecordwaskit" variable to be declared prior to it being accessed. In .NET 2.0, it appears that this will no longer work.
I need to be able to access the previous value of a variable (or previous XML element) while inside of a loop. Are there any solutions to this problem with .NET 2.0?
Thanks,
Jody
<xsl:for-each select="Order/Invoice/InvoiceDetails/InvoiceDetail">
<xsl:variable name="iskit">
<xsl:choose>
<xsl:when test="@idt_set_master='N' and @idt_set_component_seq>0">
1
</xsl:when>
<xsltherwise>
0
</xsltherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="position()>1">
<xsl:if test="$lastrecordwaskit=1 and $iskit=0">
<tr>
<td> </td>
</tr>
</xsl:if>
</xsl:if>
{Additional Code ...}
<xsl:variable name="lastrecordwaskit"><xsl:value-of select="$iskit"/></xsl:variable>
</xsl:for-each>
System.Xml.Xsl.XslLoadException: The variable or parameter 'lastrecordwaskit' was duplicated within the same scope. An error occurred at (174,12).
at System.Xml.Xsl.XslCompiledTransform.LoadInternal(Object stylesheet, XsltSettings settings, XmlResolver stylesheetResolver)
at System.Xml.Xsl.XslCompiledTransform.Load(XmlReader stylesheet)
at MyProject.MyClass.TranslateXML(String xsltFileName, String xmlText) in C:\Source\MySolution\MyProject\MyClass.vb:line 155
I have included the XSL code below which is related to the issue. In order to maintain the previous value of "iskit", I am declaring a variable "lastrecordwaskit" at the end of the loop. Near the beginning of the loop, prior to the variable declaration of "lastrecordwaskit", I am checking for "position() > 1" before trying to access "lastrecordwaskit". In .NET 1.1, this would allow the "lastrecordwaskit" variable to be declared prior to it being accessed. In .NET 2.0, it appears that this will no longer work.
I need to be able to access the previous value of a variable (or previous XML element) while inside of a loop. Are there any solutions to this problem with .NET 2.0?
Thanks,
Jody
<xsl:for-each select="Order/Invoice/InvoiceDetails/InvoiceDetail">
<xsl:variable name="iskit">
<xsl:choose>
<xsl:when test="@idt_set_master='N' and @idt_set_component_seq>0">
1
</xsl:when>
<xsltherwise>
0
</xsltherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="position()>1">
<xsl:if test="$lastrecordwaskit=1 and $iskit=0">
<tr>
<td> </td>
</tr>
</xsl:if>
</xsl:if>
{Additional Code ...}
<xsl:variable name="lastrecordwaskit"><xsl:value-of select="$iskit"/></xsl:variable>
</xsl:for-each>