[xquery-talk] Issues with recursive fn:transform

Ihe Onwuka ihe.onwuka at gmail.com
Mon Nov 16 08:07:29 PST 2020


Below is a recursive fn:transform function.
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

   <xsl:function name="local:x" as="element()+">
      <xsl:param name="currentVersion" as="element()"/>
      <xsl:param name="accum" as="element()+"/>
      <xsl:sequence select="if (namespace-uri($currentVersion/*) =>
contains($finalTarget))
                            then ($currentVersion,$accum)
                            else local:x(fn:transform(map {
                                                       'stylesheet-node' :
 doc(''),
                                      'source-node'     :  $currentVersion
                                              })?output/*,
                        $accum)"/>
   </xsl:function>

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

XPTY0004  The required item type of the first argument of local:x() is
element(); the
  supplied value doc(.../translator.xsl) does not match. The supplied value
is a document node
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20201116/b288040a/attachment.html>


More information about the talk mailing list