links, trees, forest, infinity

On mapping from Scheme values to libxml nodes. It is reasonable to map the same physical values to the same physical nodes. But it causes unexpected results. Consider the stylesheet:

<x:stylesheet
  xmlns:x = "http://www.w3.org/1999/XSL/Transform"
  xmlns:s = "http://uucode.com/xslt/scheme"
  x:extension-element-prefixes="s"
  version     = "1.0">

<s:init>
  (define foo 777)
</s:init>

<x:template match="/">
  <x>
    <s:scheme>foo</s:scheme>
    <s:scheme>foo</s:scheme>
    <!-- <y><s:scheme>foo</s:scheme></y> -->
  </x>
</x:template>

</x:stylesheet>

One can expect to get the following result:

<x>777777</x>

But the right answer is:

<x>777</x>

As I found, libxml performs a set of checks while adding a child. One of the checks is that the same node isn't inserted twice.

And what happens when the part of stylesheet is uncommented? It produces such a tree structure which isn't expected by libxml. As result, serializer enters infinitive loop till core dump.

Categories: Generative XML

Updated: