MINI MINI MANI MO

Path : /opt/oracle/product/18c/dbhomeXE/rdbms/xml/xsl/
File Upload :
Current File : //opt/oracle/product/18c/dbhomeXE/rdbms/xml/xsl/kusviewd.xsl

<?xml version="1.0"?>
<!--

 Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved.

NAME
    kusviewd.xsl
DESCRIPTION
    Convert VIEW (SXML) document to creation DDL.

MODIFIED        MM/DD/YY
    tbhukya     04/12/17 - Bug 25791822: Generate constraints in object view
    tbhukya     04/07/17 - RTI 20231817: Remove space before constraint 
                           with READ ONLY
    tbhukya     03/22/17 - Bug 25715449: Constraint with READ ONLY
    jjanosik    09/12/16 - Bug 24387072: Fix how collation clause is output
    tbhukya     08/04/16 - Bug 24313182: Add double quotes to collation name
    tojhuan    07/20/16 - lr -18954633: hide element IDs in XMLSCHEMA clauses
    tbhukya    03/15/15 - Proj 47173: Data bound collation
    abodge     06/09/14 - CM MODIFIED: Emit SQL terminator; restore column order
    rapayne    05/20/14 - fix editionable compatibility.
    lbarton    02/12/14 - bug 17943479: import kustablc
    rapayne    01/20/13 - bug 15917102: add BEQUEATH and EDITIONABLE support.
    lbarton    01/26/12 - gravipat_bug-12667763: CONTAINER_DATA keyword
    lbarton    07/24/09 - bug 8342311: view subquery restriction clause
    rapayne    05/04/09 - Add READ ONLY for PARSED_SUBQUERY
    rapayne    12/09/08 - add COMMENTS support from CM code stream.
    lbarton    01/10/07 - PARSED_QUBQUERY
    akruglik   09/07/06 - Column Map Views got rechristened as Editioning Views
    rapayne    06/07/06 - add support for editioning views.
    lbarton    03/27/06 - bug 5118027: CONSTRAINTS and REF_CONSTRAINTS params 
                          for SXMLDDL 
    sdavidso   11/02/05 - fix inconsistent stylesheet format 
    htseng     09/08/05 - separate schemaname and name in under_clause 
    lbarton    08/10/05 - lbarton_mddiff
    htseng     05/16/05 - Initial version
 -->
<xsl:stylesheet version="1.0" xmlns:sxml="http://xmlns.oracle.com/ku" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <!-- Top level imports -->
 <xsl:import href="kuscommd.xsl"/>
 <xsl:import href="kuscnstd.xsl"/>
 <xsl:import href="kusparsd.xsl"/>
 <xsl:import href="kustablc.xsl"/>
 <!-- Top-level parameters -->
 <!-- Parameters for DDL generation -->
 <xsl:param name="PRETTY">1</xsl:param>
 <xsl:param name="FORCE">1</xsl:param>
 <xsl:param name="REPLACE">1</xsl:param>
 <xsl:param name="SQLTERMINATOR">0</xsl:param>
 <xsl:param name="CONSTRAINTS">1</xsl:param>
 <xsl:param name="REF_CONSTRAINTS">1</xsl:param>
 <!-- Params for genetrating comments ddl (Change Mgr) -->
 <xsl:param name="COMMENTS">0</xsl:param>
 <!-- Parameter to place columns in original order (CM) -->
 <xsl:param name="REORDER_COLUMNS">0</xsl:param>
 <!-- *******************************************************************
Template: top-level template for VIEW.
******************************************************************** -->
 <xsl:template match="sxml:VIEW">
  <xsl:text>CREATE</xsl:text>
  <xsl:if test="$REPLACE=1">
   <xsl:text> OR REPLACE</xsl:text>
  </xsl:if>
  <xsl:if test="$FORCE=1"> FORCE</xsl:if>
   <xsl:if test="$VERSION>=1200000000">
    <xsl:choose>
     <xsl:when test="sxml:NONEDITIONABLE"> NONEDITIONABLE</xsl:when>
     <xsl:otherwise> EDITIONABLE</xsl:otherwise>
    </xsl:choose>
   </xsl:if>
  <xsl:if test="sxml:EDITIONING_VIEW">
   <xsl:text> EDITIONING </xsl:text>
  </xsl:if>
  <xsl:text> VIEW </xsl:text>
  <xsl:text>"</xsl:text>
  <xsl:value-of select="sxml:SCHEMA"/>
  <xsl:text>"."</xsl:text>
  <xsl:value-of select="sxml:NAME"/>
  <xsl:text>" </xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa; </xsl:text>
  </xsl:if>
  <xsl:choose>
   <xsl:when test="sxml:COL_LIST">
    <xsl:apply-templates select="sxml:CONTAINER_DATA"/>
    <!-- relational_view_clause -->
    <xsl:text>( "</xsl:text>
    <xsl:choose>
     <xsl:when test="$REORDER_COLUMNS=1">
      <xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM">
       <xsl:sort select="sxml:COL_NUM" data-type="number"/>
       <xsl:value-of select="sxml:NAME"/>
       <xsl:if test="position()!=last()">", "</xsl:if>
      </xsl:for-each>
     </xsl:when>
     <xsl:otherwise>
      <xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM">
       <xsl:value-of select="sxml:NAME"/>
       <xsl:if test="position()!=last()">", "</xsl:if>
      </xsl:for-each>
     </xsl:otherwise>
    </xsl:choose>
    <xsl:text>"</xsl:text>
    <xsl:if test="sxml:CHECK_CONSTRAINT_LIST or
                  sxml:PRIMARY_KEY_CONSTRAINT_LIST or
                  sxml:UNIQUE_KEY_CONSTRAINT_LIST or
                  sxml:FOREIGN_KEY_CONSTRAINT_LIST or
                  sxml:SCOPE_CONSTRAINT_LIST or
                  sxml:ROWID_CONSTRAINT_LIST">
     <xsl:text>, </xsl:text>
    </xsl:if>
    <xsl:if test="$PRETTY=1">
     <xsl:text>&#xa; </xsl:text>
    </xsl:if>
    <xsl:call-template name="Constraints">
     <xsl:with-param name="ParentNode" select="."/>
    </xsl:call-template>
    <xsl:text> ) </xsl:text>
   </xsl:when>
   <xsl:when test="sxml:OF_TYPE">
    <!-- object_view_clause -->
    <xsl:apply-templates select="sxml:OF_TYPE"/>
   </xsl:when>
   <!-- XML_type_view_clause -->
   <xsl:when test="sxml:OF_XMLTYPE">
    <xsl:apply-templates select="sxml:OF_XMLTYPE"/>
   </xsl:when>
  </xsl:choose>
  <!-- Default collation clause -->
  <xsl:if test="$VERSION>=1202000000 and sxml:DEFAULT_COLLATION">
   <xsl:call-template name="DoCollation">
    <xsl:with-param name="IsDefault">1</xsl:with-param>
    <xsl:with-param name="Name" select="sxml:DEFAULT_COLLATION"/>
   </xsl:call-template>
  </xsl:if>
  <xsl:if test="sxml:BEQUEATH">
   <xsl:text> BEQUEATH </xsl:text>
   <xsl:value-of select="sxml:BEQUEATH"/>
  </xsl:if>
  <!-- SUBQUERY or PARSED_SUBQUERY -->
  <xsl:apply-templates select="sxml:SUBQUERY"/>
  <xsl:apply-templates select="sxml:PARSED_SUBQUERY"/>
  <!-- subquery restriction -->
  <xsl:apply-templates select="sxml:RESTRICTION">
   <xsl:with-param name="Parsed" select="string-length(sxml:PARSED_SUBQUERY)!=0"/>
  </xsl:apply-templates>
  <xsl:if test="$SQLTERMINATOR=1">
   <xsl:text>;</xsl:text>
  </xsl:if>
  <!-- COMMENTS -->
  <xsl:if test="$COMMENTS=1 and sxml:COMMENTS">
   <xsl:call-template name="CommentsOn">
    <xsl:with-param name="ObjectType">TABLE</xsl:with-param>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:CONTAINER_DATA">
  <!-- *******************************************************************
Template: CONTAINER_DATA
******************************************************************** -->
  <xsl:text> CONTAINER_DATA </xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;  </xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:SUBQUERY">
  <!-- *******************************************************************
Template: SUBQUERY
******************************************************************** -->
  <xsl:text> AS </xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;  </xsl:text>
  </xsl:if>
  <xsl:value-of select="."/>
 </xsl:template>
 <xsl:template match="sxml:PARSED_SUBQUERY">
  <!-- *******************************************************************
Template: PARSED_SUBQUERY
******************************************************************** -->
  <xsl:text> AS </xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;  </xsl:text>
  </xsl:if>
  <xsl:apply-templates select="*[1]">
   <xsl:with-param name="InnerQuery">0</xsl:with-param>
  </xsl:apply-templates>
 </xsl:template>
 <!-- *******************************************************************
Template: OF_TYPE
******************************************************************** -->
 <xsl:template match="sxml:OF_TYPE">
  <xsl:text> OF </xsl:text>
  <xsl:call-template name="SchemaName">
   <xsl:with-param name="ParentNode" select="."/>
  </xsl:call-template>
  <xsl:apply-templates select="sxml:WITH_OBJECT_IDENTIFIER"/>
  <xsl:apply-templates select="sxml:UNDER"/>
  <!-- constraints -->
  <xsl:if test="sxml:CHECK_CONSTRAINT_LIST or
                sxml:PRIMARY_KEY_CONSTRAINT_LIST or
                sxml:UNIQUE_KEY_CONSTRAINT_LIST or
                sxml:FOREIGN_KEY_CONSTRAINT_LIST or
                sxml:SCOPE_CONSTRAINT_LIST or
                sxml:ROWID_CONSTRAINT_LIST">
   <xsl:text> ( </xsl:text>
   <xsl:call-template name="Constraints">
    <xsl:with-param name="ParentNode" select="."/>
   </xsl:call-template>
   <xsl:text> ) </xsl:text>
  </xsl:if>
 </xsl:template>
 <!-- *******************************************************************
Template: WITH_OBJECT_IDENTIFIER
******************************************************************** -->
 <xsl:template match="sxml:WITH_OBJECT_IDENTIFIER">
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa; </xsl:text>
  </xsl:if>
  <xsl:text> WITH OBJECT IDENTIFIER (</xsl:text>
  <xsl:for-each select="sxml:ATTRIBUTE_LIST/sxml:ATTRIBUTE_LIST_ITEM">
   <xsl:value-of select="sxml:NAME"/>
   <xsl:if test="position()!=last()">,</xsl:if>
  </xsl:for-each>
  <xsl:text>) </xsl:text>
 </xsl:template>
 <!-- *******************************************************************
Template: UNDER
******************************************************************** -->
 <xsl:template match="sxml:UNDER">
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa; </xsl:text>
  </xsl:if>
  <xsl:text> UNDER </xsl:text>
  <!-- UNDERTEXT does NOT always have the schema name and if present is not quoted.
       On the other hand it does contain a quoted object name if necessary.
       So. we just need to ensure the schema is properly quoted
   -->
  <xsl:if test="sxml:SCHEMA">
   <xsl:call-template name="SourceName">
    <xsl:with-param name="NameNode" select="sxml:SCHEMA"/>
   </xsl:call-template>
   <xsl:text>.</xsl:text>
  </xsl:if>
  <xsl:value-of select="sxml:NAME"/>
  <xsl:text> </xsl:text>
 </xsl:template>
 <xsl:template match="sxml:OF_XMLTYPE">
  <!-- *******************************************************************
Template: OF_XMLTYPE
******************************************************************** -->
  <xsl:text> OF XMLTYPE </xsl:text>
  <xsl:apply-templates select="sxml:XMLSCHEMA"/>
  <xsl:apply-templates select="sxml:ELEMENT"/>
  <xsl:apply-templates select="sxml:WITH_OBJECT_IDENTIFIER"/>
 </xsl:template>
 <xsl:template match="sxml:RESTRICTION">
  <xsl:param name="Parsed" select="false()"/>
  <!-- *******************************************************************
Template: RESTRICTION
Parameters:
 Parsed - TRUE = view SXML doc contains parsed subquery
******************************************************************** -->
  <xsl:if test="$Parsed">
   <xsl:apply-templates select="sxml:READ_ONLY"/>
   <xsl:apply-templates select="sxml:CHECK_OPTION"/>
  </xsl:if>
  <xsl:apply-templates select="sxml:CHECK_OPTION/sxml:CONSTRAINT|sxml:READ_ONLY/sxml:CONSTRAINT">
   <xsl:with-param name="Parsed" select="$Parsed"/>
  </xsl:apply-templates>
 </xsl:template>
 <xsl:template match="sxml:READ_ONLY">
  <xsl:text> WITH READ ONLY</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:CHECK_OPTION">
  <xsl:text> WITH CHECK OPTION</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:CHECK_OPTION/sxml:CONSTRAINT|sxml:READ_ONLY/sxml:CONSTRAINT">
  <xsl:param name="Parsed" select="false()"/>
  <xsl:choose>
   <xsl:when test="$Parsed">
    <xsl:text> CONSTRAINT "</xsl:text>
   </xsl:when>
   <xsl:otherwise>
    <!-- Space before constraint is not needed as subquery text contains it -->
    <xsl:text>CONSTRAINT "</xsl:text>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="."/>
  <xsl:text>"</xsl:text>
 </xsl:template>
</xsl:stylesheet>

OHA YOOOO