Oracle PLSQL: xmltype.transform vs xmltransform

江枫思渺然 提交于 2019-12-02 07:11:26

问题


Since we have moved the database from 11.2.0.2.0 to 11.2.0.4.0 xmltype.transform function had got a specific behaviour.

The problem is that before it did not work fine: it replaced all tags with open-close version (e.g. it did replace <br /> with <br></br>), but I could live with it. Now it behaves the other way round (replaces everything with one tag) and it makes a big problem with <script></script> tag, because this tag must be explicitly closed with a </script> otherwise the browser thinks it is not closed, even if it is closed so <script /> => all web pages are corrupted now.

Example:

declare
  xml      xmltype := new xmltype('<?xml version="1.0" encoding="ISO-8859-1"?><document></document>');
  xsl      xmltype := new xmltype('<?xml version="1.0" encoding="ISO-8859-1"?>
                                   <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                                     <xsl:output method="html" />
                                     <xsl:template match="/">
                                       <html>
                                         <head>
                                           <script type="text/javascript" src="jquery-1.11.1.min.js"></script>
                                         </head>
                                         <body>
                                           <br />
                                         </body>
                                       </html>
                                     </xsl:template>
                                   </xsl:stylesheet>');
begin
  dbms_output.put_line(xml.transform(xsl,null).getclobval());
end;

In 11.2.0.2.0 this works like this:

<html><head><script src="jquery-1.11.1.min.js"></script></head><body><br></br></body></html>

In 11.2.0.4.0 it works different:

<html>
  <head>
    <script type="text/javascript" src="jquery-1.11.1.min.js"/>
  </head>
  <body>
    <br/>
  </body>
</html>

I guess the problem is in formatting, but I did not set up anything else to enable it...

What is interesting, I've found this article with another problem, but with the same workaround as a solution:

select xmltransform(xmltype('<?xml version="1.0" encoding="ISO-8859-1"?><document></document>'),
                    xmltype('<?xml version="1.0" encoding="ISO-8859-1"?>
                             <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
                               <xsl:output method="html" />
                               <xsl:template match="/">
                                 <html>
                                   <head>
                                     <script src="jquery-1.11.1.min.js"></script>
                                   </head>
                                   <body>
                                     <br />
                                   </body>
                                 </html>
                               </xsl:template>
                             </xsl:stylesheet>')) html
from dual

this just works in every version and gives a proper result (the one with doubled <br />, but as I've said, it does not matter to me).

In Oracle documentation there is nothing said about the difference in these functions; they even say many times that they are the same functions (see here).

I will, of course, use this workaround, but, please, tell me: is it possible to make it work again without changing the code?

What is the reason of this behaviour?

Thank you in advance.

来源:https://stackoverflow.com/questions/24486716/oracle-plsql-xmltype-transform-vs-xmltransform

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