<div dir="ltr"><div><div>Below is a recursive fn:transform function. </div><div>Takes 2 arguments - the XML and the accumulator and recursively calls a translator.xsl to generate a translation of the XML into the next version. That's what is supposed to happen, it infinitely loops because the next version of the XML is being generated so the base case is never true - can't see a reason why that should happen but for now I will settle for hopefully understanding something more straightforward</div><div><br></div><div>   <xsl:function name="local:x" as="element()+"><br>      <xsl:param name="currentVersion" as="element()"/><br>      <xsl:param name="accum" as="element()+"/><br>      <xsl:sequence select="if (namespace-uri($currentVersion/*) => contains($finalTarget)) <br>                            then ($currentVersion,$accum)<br>                            else local:x(fn:transform(map { <br>                                                       'stylesheet-node' :  doc(''),<br>                                                'source-node'     :  $currentVersion<br>                                                    })?output/*,<br>                             $accum)"/> <br>   </xsl:function><br></div></div><div><br></div><div><div>I have used the old doc('') trick to pass the current stylesheet (the name is translator.xsl) to the recursive call but that is not the value supplied as the first argument of local:x but the error message says it is </div><div><br></div><div>XPTY0004  The required item type of the first argument of local:x() is element(); the<br>  supplied value doc(.../translator.xsl) does not match. The supplied value is a document node</div></div></div>