Jump to content

Browser limit


lucianmli
 Share

Recommended Posts

Hello I have an XML of about 200KB fetched trough ajax and parsed with an XSLT. The problem is when I parse each node without recursiveness (simply xsl:for-each select="//mynode") it works fine, but whem i do it with apply template for child nodes, to keep the tree structure, id doesn't show anything not even the static xslt data(html code not from XML). I tried with the try it yourself editor step by step by adding branch nodes, and worked ....for a few level but after that: nada, niente, nix...in other words it doesn't work. Tried diferent nodes, even repeated nodes, same result after say 5 depth levels it stops. Why doesn't it crash when I do the non recursive parse, does the program heap fill? Is there a way to call recursive parse so that it doesn't crash? In editix2010 IT DOES ALL THE PARSING NO CRASH NO ERROR!! I'm leaving work now so I can't get the sources... so until next time maibe someone else encountered the problem. Thanks!

Edited by lucianmli
Link to comment
Share on other sites

A recursion generally involves the use of a call stack for each depth level, which in turn means memory can quickly run out if each stack level has a lot of stuff going for it.In a loop, at the end of each iteration, the previous context is discarded, so the memory runs out less quickly.If your XML followed a structure in which a single for-each is replaced by a single apply-templates, there should be no difference. However, if you use apply-templates for the sake of recursion (one apply-templates replaces a few for-each elements), that takes up memory... a little too much memory in the case of browsers it seems. I'm guessing that's because the browser has more responsibilities than an XSLT processor in an editor or a server scripting language (i.e. it needs to update many things in the JavaScript engine and browser add-ons).There are several ways out of this situation, but none is perfect - increase your (clients') RAM (definetly a bad idea), use a server side XSLT processor (assuming you have enough RAM there and are OK with giving clients only the resulting document), keep using for-each (acceptable if that's the way your XML is made for; bad idea in other scenarios).

Link to comment
Share on other sites

would it be ok if i strip the xml of the data just keep the id to build the tree and then fatten the tree with data via js? Do i need another stripped down xml or the xslt simplicity do, I can't try it miself right now since i don't have the means to replicate the data?ex:xslt:...<xsl:template match="/"><html><body><xsl:for-each select="root/node"><xsl:apply-templates select="."/></xsl:for-each></body></html></xsl:template><xsl:template match="node"><div><xsl:attribute name="id"> <xsl:value-of select="id"/></xsl:attribute><xsl:apply-templates select="node"/></div>...xml:<root><node><id>x</id><data>sdadsadads</data> <node> <id>x</id> <data>sdadsadads</data> <node> <id>x</id> <data>sdadsadads</data> .....N levels.... </node> </node></node><node><id>x</id><data>sdadsadads</data></node></root>

Link to comment
Share on other sites

And you're saying the ONLY replacement you're doing is the main for-each, and you're already reaching the limit?!?This can only mean memory leak in whichever browser you're using. The only solution, short of keep using for-each, is to use a server side XSLT processor. The reason your editor didn't fail is because the XSLT processor it's using doesn't have this memory leak.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...