473,394 Members | 1,870 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 1341
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Bernd Fuhrmann | last post by:
Hi! I have some trouble with some simple stupid XSLT-stuff. My stylesheet: ------------- <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0"...
5
by: Clifford W. Racz | last post by:
Has anyone solved the issue of translating lists in Word 2003 (WordML) into xHTML? I have been trying to get the nested table code for my XSLT to work for a while now, with no way to get the...
7
by: Rolf Kemper | last post by:
Dear All, somehow I remember that such or similar question was discussed already somewhere. But I can't find it anymore. I have a template calling itself. As long it goes deeper into the...
5
by: ChrisEvans | last post by:
Hi there, I've got an XML file which uses an XSL stylesheet. Problem is: <br /> tags don't work for me when the content is gathered from the xml. Example: <main> <title>Hi</title>
6
by: Hendrik Schober | last post by:
Hi, I have a problem with extending some existing code. In a simplified form, the problem looks like this: I have four types, A, B, C, and D. Each A refers to zero, one, or more B's and each...
3
by: @CL | last post by:
Hi,all I was confused with xml transform. I had a xml file like: <Details> <names> <name/> <name/> ......or more <name/> </names>
5
by: monmonja | last post by:
Hi i'm new to xsl and i have been using smarty php templating but its just so hard to read codes in smarty/php/flash than xml/xsl/flash, i rather sacrifice speed then not being able to read code...
2
by: felciano | last post by:
Hello -- I am trying to use XSL to process Amazon wishlist data to sort the results by type (Apparel, then Books, then DVDs, etc). Amazon's web services chunk up results in multiple pages of...
4
by: andreyvul | last post by:
I have a template function like this: std::vector<std::pair<Square<T>, Triangle<T * recarrow(T a, T b, int n) { /* ... */ } template <class T> struct Square { /* ... */ };
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.