[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Too many apply-templates call error -- can't figure ou

Subject: Too many apply-templates call error -- can't figure out what causes the error
From: UlyLee <ulyleeka@xxxxxxxxx>
Date: Fri, 18 Nov 2005 02:11:57 -0800 (PST)
figure ou
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 &lt; 10) then
concat('replacement','00',$value) else if ($value &gt;
9 and $value &lt; 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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.