xml - EXSLT custom function causes stylesheet to return "too many nested apply-templates calls" error -


i tried implement "ternary operator" extension function use in stylesheet using exslt's func:function element. compatibility reasons, have use xslt 1.0. came this:

<func:function name="myext:ternary">   <xsl:param name="expr" />   <xsl:param name="iftrue" />   <xsl:param name="iffalse" />    <func:result>     <xsl:choose>       <xsl:when test="boolean($expr)"><xsl:value-of select="$iftrue"/></xsl:when>       <xsl:otherwise><xsl:value-of select="$iffalse" /></xsl:otherwise>     </xsl:choose>   </func:result> </func:function> 

and works fine wherever use it. however, tried implement substring-after-last function (from here). code works fine:

<func:function name="myext:substring-after-last">   <xsl:param name="string" select="''"/>   <xsl:param name="delimiter" select="$d" />    <func:result>     <xsl:choose>       <xsl:when test="contains($string, $delimiter)">         <xsl:value-of select="myext:substring-after-last(substring-after($string, $delimiter), $delimiter)"/>       </xsl:when>       <xsl:otherwise>         <xsl:value-of select="$string"/>       </xsl:otherwise>     </xsl:choose>   </func:result> </func:function> 

this way works:

[…]   <func:result>     <xsl:if test="not(contains($string, $delimiter))">       <xsl:value-of select="$string"/>     </xsl:if>     <xsl:if test="not($string='')">       <xsl:value-of select="myext:substring-after-last(substring-after($string, $delimiter), $delimiter)"/>     </xsl:if>   </func:result> </func:function> 

… when try implementation using "ternary" function, not work;

this doesn't work:

<func:result>   <xsl:value-of select="myext:ternary(     contains($string, $delimiter) , not($string = ''),     myext:substring-after-last(substring-after($string, $delimiter), $delimiter),     $string   )"/> </func:result> 

this method results in stylesheet throwing error @ me:

error @ xsl:apply-templates on line 49 of file:/[my_main_file].xsl:   many nested apply-templates calls transformation failed: run-time errors reported 

i've tried increase java's stack size using -xss16m switch, results in saxon throwing outofmemoryerror (java heap space). data sets send function rather small, don't understand overflow happens , why should necessary me try increase stack size.

what doing wrong?

i tried implement "ternary operator" extension function

use union of position predicate negation predicate variable check else statement:

//var[1] | //var[not //var] 

use concatenation of mutually exclusive expressions ternary idiom:

concat("(",substring(translate(., "()-", ""), 1, 3), ")", substring(translate(., "()-", ""), 4, 3), "-", substring(translate(., "()-", ""), 7, 4))) 

in xpath number(true()) 1, while number(false()) 0 , when second argument of substring() function greater actual length of string, empty string returned. hence substring($s1, number(not($condition))*string-length($s1)+1) returns $s1 if $condition true , empty string otherwise. concatenating 2 such expressions in mutually exclusive way gives conditional strings expression.

references


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -