1 Reply Latest reply: Oct 29, 2012 3:03 PM by odie_63 RSS

    Convert XML to HTML

    932936
      All,

      Version Info:
      Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
      PL/SQL Release 11.2.0.2.0 - Production
      CORE     11.2.0.2.0     Production
      TNS for Linux: Version 11.2.0.2.0 - Production
      NLSRTL Version 11.2.0.2.0 - Production

      My question:
      I have a query that I converted to XML using DBMS_XMLGEN. Right now the result is stored as CLOB, but I can store it as XMLTYPE if it will be easier for what I'm trying to do.

      I would like to take my XML documentation and convert it to an HTML Table for the purposes of including this inside of an e-mail (using UTL_MAIL). I can already create an HTML table manually if I explicitly name each column and do a lot of crud, but ideally I was hoping I could leverage XML somehow to make these kinds of reports easier to send to my end-users.

      Does anyone know if this is possible to do straight from Oracle and if so, what libraries I should be looking at?

      Thanks.
        • 1. Re: Convert XML to HTML
          odie_63
          Does anyone know if this is possible to do straight from Oracle and if so, what libraries I should be looking at?
          XSLT can do the job nicely.

          Oracle offers some interfaces to apply an XSLT stylesheet to any XMLType instance :

          - XMLTransform function
          - XMLType's transform method (now deprecated)
          - DBMS_XSLPROCESSOR package
          - DBMS_XMLGEN

          You can look those up in the documentation for your version to see how to use them :
          http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb08tra.htm#g1030361

          Since you've started with DBMS_XMLGEN (wouldn't have been my first choice), you can use the setXSLT procedure to associate an XSLT stylesheet to the context so that the transformation is performed on-the-fly.

          You'll find tons of XSLT examples about converting XML to HTML on the Internet.

          Here's one I wrote last year to answer a similar question :
          {message:id=9371097}