XSLTProcessor::transformToUri(): Memory allocation failed : reaching arbitrary MAX_URI_LENGTH limit

萝らか妹 提交于 2021-01-29 17:36:45

问题


I have some XML files that I need to "transform" in Html and display on screen.

I have developed a simple script that works -almost- all of the times, using DOMDocument and XSLTProcessor.

The problem is that sometimes it gives this error, and the resulting html is only a part of the complete content:

XSLTProcessor::transformToUri(): Memory allocation failed : reaching arbitrary MAX_URI_LENGTH limit in /var/www/test/index.php on line 14

This is a working copy of my script, which gives the same error with the same files.

<?php
$xslPath = 'test.xsl';
$xmlString = file_get_contents('test.xml');

$xml = new DOMDocument;
$xml->loadXML($xmlString);

$xsl = new DOMDocument;
$xsl->load($xslPath);

$proc = new XSLTProcessor;
$proc->importStyleSheet($xsl);

$proc->transformToURI($xml, 'php://output');

I have tried to save the output to a file, but still I am having the same error, so php://output shouldn't be the a problem. How can I solve this issue?

EDIT: It looks like the problem lies in the following code. If fact, if I remove the following lines, I am no longer seeing the issue. I hope this helps:

<a name="link" href="data:{$mimeType}/{$format};base64,{normalize-space(Attachment)}" download="{$attachmentName}">
    <xsl:value-of select="attachmentName" />
</a>

The attachment itself is a base64 pdf file (which in this case is a ~1mb string, but it could be even more)

EDIT 2: This is what happens if I try to generate the html using the command line xsltproc command:

xsltproc --stringparam target cora_cmd test.xsl test.xml > test.html
URI error : Memory allocation failed : reaching arbitrary MAX_URI_LENGTH limit
URI error : Memory allocation failed : escaping URI value

EDIT 3: I have tried replacing transformToURI with transformToXML, no results. libxml_get_errors() shows no results too.

来源:https://stackoverflow.com/questions/60875571/xsltprocessortransformtouri-memory-allocation-failed-reaching-arbitrary-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!