Subject: Re: [xsl] Too many apply-templates call error -- can't figure out what causes the error From: Mike Ferrando <mikeferrando@xxxxxxxxx> Date: Fri, 18 Nov 2005 07:01:44 -0800 (PST) |
UlyLee, I just had a similiar error message. Although my issues were different, I would suggest creating a template that is specifically for the root node and one that is for all descendants. <xsl:template match="/"> <xsl:apply-templates select="*[not(parent::*)] </xsl:template> <xsl:template match="*[not(parent::*)]"> <!-- you code here --> </xsl:template> <xsl:template match="*"> <!-- your code here --> </xsl:template> This simplistic approach might solve your problem. You can rewrite this in 2.0 however you want. I use XSLT 1.0. Mike Ferrando Library Technician Library of Congress Washington, DC 202-707-4454 --- UlyLee <ulyleeka@xxxxxxxxx> wrote: > I'm running an xsl transformation using saxon 8.6 and > i encounter this error, 'too many apply-template > calls'. The purpose of the xslt is to tag all strings > in the listEXP.txt file with EXP. I have 2 templates > to match, 1st the template that matches * which simply > copies the element and its attributes. the 2nd is a > template that matches text()[name(parent::*)!='EXP'], > here it should search all the occurrences of the > strings and tag it with EXP. > > I have created two functions, 1 is the tmpReplacement > function which creates a tree of strings that i will > use as temporary replacement strings. and the other is > the replace-all function that do the search and > replace function. > > the error message points me to the apply-templates in > the template that matches * but i think thats not the > one actually causing the error because when i remove > the elements that calls the replace-all function the > transformation is a success. > > so i think the error is in the replace-all function > but i can't seem to find out which part of the > function is actually causing it. > > this is the xsl file: > > <?xml version="1.0" encoding="UTF-8"?> > <xsl:stylesheet version="2.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > xmlns:f="data:,f"> > <xsl:output method="xml" version="1.0" > encoding="utf-8" indent="yes"/> > <xsl:variable name="wordLst" as="xs:string*"> > <xsl:analyze-string > select="unparsed-text('listEXP.txt','utf-8')" > regex="[\r\n]"> > <xsl:non-matching-substring> > <xsl:value-of select="."/> > </xsl:non-matching-substring> > </xsl:analyze-string> > </xsl:variable> > <xsl:template match="/"> > <xsl:apply-templates/> > </xsl:template> > <xsl:template match="*"> > <xsl:element name="{name(.)}"> > <xsl:copy-of select="@*"/> > <xsl:apply-templates/> > </xsl:element> > </xsl:template> > <xsl:template match="text()[name(parent::*)!='EXP']"> > <xsl:variable name="repLst" as="xs:string*" > select="for $i in (1 to count($wordLst)) return > f:tempReplacement($i)"/> > <xsl:variable name="tmpStr" > select="f:replace-all(.,$wordLst,$repLst,1)"/> > <xsl:value-of > select="f:replace-all($tmpStr,$repLst,$wordLst,0)"/> > </xsl:template> > <!--Function that creates a tree node of temporary > replacement strings.--> > <xsl:function name="f:tempReplacement" as="xs:string"> > <xsl:param name="value" as="xs:integer"/> > <xsl:value-of select="if ($value < 10) then > concat('replacement','00',$value) else if ($value > > 9 and $value < 100) then > concat('replacement','0',$value) else > concat('replacement',$value)"/> > </xsl:function> > <!--Function that simulates a replace-all function and > returns the replaced string.--> > <xsl:function name="f:replace-all"> > <xsl:param name="input" as="xs:string"/> > <xsl:param name="words-to-replace" as="xs:string*"/> > <xsl:param name="replacement" as="xs:string*"/> > <xsl:param name="flag" as="xs:integer"/> > <xsl:choose> > <xsl:when test="$flag=1"> > <xsl:sequence select="if (exists($words-to-replace)) > then f:replace-all(replace($input, > replace($words-to-replace[1], '[.\\?*+{}()\[\]^$]', > '\\$0'), > $replacement[1],'i'),remove($words-to-replace,1),remove($replacement,1),1) > else $input"/> > </xsl:when> > <xsl:otherwise> > <xsl:sequence select="if (exists($words-to-replace)) > then f:replace-all(replace($input, > replace($words-to-replace[1], '[.\\?*+{}()\[\]^$]', > '\\$0'), > concat('<EXP>',$replacement[1],'</EXP>')),remove($words-to-replace,1),remove($replacement,1),0) > else $input"/> > </xsl:otherwise> > </xsl:choose> > </xsl:function> > </xsl:stylesheet> > > this is the listEXP.txt > Faire-part > Par-dessus > S. Prieure > dernier-ni > sang-froid > sage-femme > Brise-bise > branle-bas > ` peu prhs > > here is the source xml: > <?xml version="1.0" encoding="ISO-8859-1"?> > <CORPUS> > <T1> > <LIB> > <T>1901-1913</T>trois cent soixante-cinq > chambres ` coucher > <EXP>Faire-part</EXP> > Faire-part > sage-femme > Brise-bise > branle-bas > ` peu prhs > </LIB> > </T1> > </CORPUS> > > > thanks, > UlyLee > > > > > > __________________________________ > Yahoo! Mail - PC Magazine Editors' Choice 2005 > http://mail.yahoo.com > > __________________________________ Yahoo! Mail - PC Magazine Editors' Choice 2005 http://mail.yahoo.com
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Too many apply-templates , Michael Kay | Thread | [xsl] setURIResolver, Fraser Goffin |
RE: [xsl] Static type-checker, drkm | Date | RE: [xsl] special characters decima, Mingqiang Yu |
Month |