problem with xmltransform
GRBMay 29 2012 — edited May 29 2012Because we have had to outsource some work, I've had to create a function that can be called by a third party to transform xml.
I've been testing this function and it works fine except that I get an error when using   in the stylesheet, but only for html output documents.
The function replaces nbsp with #160, but the error still happens.
I've pared the stylesheet down to find out why the error happens and it's come down to the following test.
The only difference is the removal of the <html> and <body> tags.
Is there any way around this problem?
Thanks.
DECLARE
ls_xml varchar2(32767);
ls_xsl varchar2(32767);
ls_xsl2 varchar2(32767);
ls_retval varchar2(32767);
BEGIN
ls_xml := '<ProjectedValues xmlns="">
<PlanType CodeId="176721"/>
</ProjectedValues>';
ls_xsl := '<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<html>
<body>
<xsl:call-template name="WhatHappensIfIDie"/>
</body>
</html>
</xsl:template>
<xsl:template name="WhatHappensIfIDie">
<p>
this a test
</p>
</xsl:template>
</xsl:stylesheet>';
ls_xsl2 := '<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/*">
<xsl:call-template name="WhatHappensIfIDie"/>
</xsl:template>
<xsl:template name="WhatHappensIfIDie">
<p>
this a test
</p>
</xsl:template>
</xsl:stylesheet>';
ls_retval := format_xml(ls_Xml, ls_xsl);
dbms_output.put_line('Test 1');
dbms_output.put_line(ls_retval);
ls_retval := format_xml(ls_Xml, ls_xsl2);
dbms_output.put_line('Test 2');
dbms_output.put_line(ls_retval);
END;
Test 1
XML format error: ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00118: Warning: undefined entity "nbsp"
Error at line 5
Test 2
<p>
this a test
</p>
This is the function:
CREATE OR REPLACE FUNCTION EXII.Format_XML(XML IN varchar2, xsl IN varchar2 )
RETURN VARCHAR2
IS
retval VARCHAR2(32767) := NULL;
xmlin XMLTYPE;
xslin XMLTYPE;
BEGIN
-- tidy up xsl; nbsp not recognised by the parser
xmlin := XMLTYPE(xml);
xslin := XMLTYPE(REPLACE(xsl,'nbsp','#160'));
SELECT XMLTRANSFORM(xmlin,xslin).getstringval() INTO retval FROM dual;
RETURN retval;
EXCEPTION
WHEN others THEN
retval := 'XML format error: '||SQLERRM;
return retval;
END;
/
Edited by: GRB on May 29, 2012 9:27 AM