Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generate HTML Table from XML

user13410062Apr 16 2014 — edited Apr 16 2014

Hi All

In the below function I need to add HEAD and STYLE to the HTML tags but when I try to hardcode it, it gives me an XML Parsing Error.

Please can you let me know how can I achieve it?

<html>

<head>

<style>

table,th,td

{

border:1px solid black;

border-collapse:collapse;

}

</style>

</head>

<body>

<table style='width:300px'>

create or replace FUNCTION get_html_report (p_query IN VARCHAR2) RETURN  CLOB IS

  ctxh            dbms_xmlgen.ctxhandle;

  xslt_tranfsorm  XMLTYPE;

  l_mail_body     CLOB; 

BEGIN

ctxh:= dbms_xmlgen.newcontext(p_query);

 

  -- XSLT Transformation to HTML

    xslt_tranfsorm := NEW XMLTYPE('

        <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

          <xsl:template match="/ROWSET">

             <table>   

              <tr>

                 <xsl:for-each select="ROW[1]/*">

                   <th> <xsl:value-of select="name()"/></th>

                   </xsl:for-each>

                 <xsl:apply-templates/>

              </tr>

             </table>

          </xsl:template>

          <xsl:template match="ROW">

            <tr><xsl:apply-templates/></tr>

          </xsl:template>

          <xsl:template match="ROW/*">

            <td style="text-align:left;"><xsl:value-of select="."/></td>

          </xsl:template>

        </xsl:stylesheet>'); 

       

    dbms_xmlgen.setnullhandling(ctxh, dbms_xmlgen.empty_tag);

   

    dbms_xmlgen.setxslt(ctxh, xslt_tranfsorm);

   

    l_mail_body := dbms_xmlgen.getxml(ctxh);

   

    dbms_xmlgen.closecontext(ctxh);  

   

   RETURN l_mail_body;

END get_html_report;

This post has been answered by odie_63 on Apr 16 2014
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 14 2014
Added on Apr 16 2014
3 comments
2,634 views