468,121 Members | 1,473 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,121 developers. It's quick & easy.

Problem with recursive XSL templates

I've discovered a quirk of .Net System.Xml.Xsl.XSLTransfrom that doesn't
seem to exist in the MSXML2 transformation.

When calling a recursive template for the first time, don't pass a parameter
value using a variable with the same name as the parameter. This seems to
cause the original value to remain constant in all recursive calls, even if
you modify that value inside the template. To demonstrate:

<xsl:template match="/">
<xsl:param name="x"/>
<html>
<body>

<xsl:call-template name="recurse">
<xsl:with-param name="x" select="$x"/>
</xsl:call-template>

</body>
</html>

</xsl:template>

<xsl:template name="recurse">
<xsl:param name="x"/>
<xsl:param name="y" select="number(1)"/>

<xsl:if test="number($y)&lt;10">
<xsl:call-template name="recurse">
<xsl:with-param name="x" select="substring-after($x,',')"/>
<xsl:with-param name="y" select="number($y)+1"/>
</xsl:call-template>
</xsl:if>

x=<xsl:value-of select="$x"/>,y=<xsl:value-of select="$y"/><br></br>

</xsl:template>

With .Net XSLTransform, passing
"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y ,z" to the uppermost
paramter 'x', the ouput of the above is:

x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=10
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=9
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=8
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=7
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=6
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=5
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=4
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=3
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=2
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=1

(without the terminating condition on y, this would produce an infinite
loop)

whereas with MSXML2, the output is:

x=j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=10
x=i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=9
x=h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=8
x=g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=7
x=f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=6
x=e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=5
x=d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y= 4
x=c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, y=3
x=b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y, z,y=2
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=1

Aside from this being brought about by lazy parameter naming, is this a bug
in .Net's System.Xml.Xsl.XslTransform?

Paul Guz.


Nov 12 '05 #1
1 1206
Yes. This is a bug.
Expected to be fixed in 1.1 SP1
--
Sergey
-------
This posting is provided "AS IS" with no warranties, and confers no rights.

"Paul Guz" <no@spam.please> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I've discovered a quirk of .Net System.Xml.Xsl.XSLTransfrom that doesn't
seem to exist in the MSXML2 transformation.

When calling a recursive template for the first time, don't pass a parameter value using a variable with the same name as the parameter. This seems to
cause the original value to remain constant in all recursive calls, even if you modify that value inside the template. To demonstrate:

<xsl:template match="/">
<xsl:param name="x"/>
<html>
<body>

<xsl:call-template name="recurse">
<xsl:with-param name="x" select="$x"/>
</xsl:call-template>

</body>
</html>

</xsl:template>

<xsl:template name="recurse">
<xsl:param name="x"/>
<xsl:param name="y" select="number(1)"/>

<xsl:if test="number($y)&lt;10">
<xsl:call-template name="recurse">
<xsl:with-param name="x" select="substring-after($x,',')"/>
<xsl:with-param name="y" select="number($y)+1"/>
</xsl:call-template>
</xsl:if>

x=<xsl:value-of select="$x"/>,y=<xsl:value-of select="$y"/><br></br>

</xsl:template>

With .Net XSLTransform, passing
"a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y ,z" to the uppermost
paramter 'x', the ouput of the above is:

x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=10
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=9
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=8
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=7
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=6
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=5
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=4
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=3
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=2
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=1

(without the terminating condition on y, this would produce an infinite
loop)

whereas with MSXML2, the output is:

x=j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=10
x=i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=9
x=h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=8
x=g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=7
x=f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=6
x=e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y=5
x=d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,y= 4
x=c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z, y=3
x=b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y, z,y=2
x=a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x, y,z,y=1

Aside from this being brought about by lazy parameter naming, is this a bug in .Net's System.Xml.Xsl.XslTransform?

Paul Guz.

Nov 12 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

20 posts views Thread by Bernd Fuhrmann | last post: by
7 posts views Thread by Rolf Kemper | last post: by
5 posts views Thread by ChrisEvans | last post: by
6 posts views Thread by Hendrik Schober | last post: by
3 posts views Thread by @CL | last post: by
5 posts views Thread by monmonja | last post: by
4 posts views Thread by andreyvul | last post: by
18 posts views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.