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/kusource.xsl

<?xml version="1.0"?>
<!-- 
 Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
NAME
    kusource.xsl
DESCRIPTION
    XSLT stylesheet for processing source lines for type, package, etc.
NOTES
    Do NOT modify this file under any circumstance. If you wish to use this
    stylesheet with an external XML/XSL parser, first make a copy then reverse
    the comments on any xsl:import statements appearing below.

MODIFIED        MM/DD/YY
    tbhukya     01/05/15 - Bug 20319428: Declare referred params and import
                           xsl files for referred templates
    bwright     12/13/13 - Bug 17952171: Fix type versioning source lines
    bwright     11/25/13 - Bug 17801303: Diff default action for 
                           PRESERVE_TYPE_EVOLUTION for GET_DDL (no) 
                           than for DP import (yes)
    bwright     08/16/13 - Bug 17312600: Remove hard tabs from DP src code
    bwright     09/27/12 - Bug 14679947: Add import TYPE retry w/o evolution
    rapayne     08/05/12 - back out 'fix' for bug 13811951. CDATA is now
                           handled in kumodtab.xsl
    ebatbout    04/15/11 - bug 9223960 - Modify DoSourceLines to accept the
                           schema and object names.  Add support for new
                           node, post_atname_off.
    htseng      04/23/07 - bug 5690152 - add post_keyw, pre_name_len 
                           to retrieve the comment between keyword and name
    sdavidso    11/02/05 - fix inconsistent stylesheet format 
    lbarton     04/08/03 - Bug 2844111: DoSourceLines
    gclaborn    11/03/00 - change name
    lbarton     07/18/00 - bugfix
    lbarton     03/17/00 - Add module header
 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <!-- Needed for templates DoParse, QuoteObject -->
 <xsl:import href="kucommon.xsl"/>
 <!-- Top-level parameters -->
 <xsl:param name="EXPORT">0</xsl:param>
 <xsl:param name="PRESERVE_TYPE_EVOLUTION">3</xsl:param>
 <!-- This template takes one variable OBJTYPE
     0 = source lines are for type or package (default)
     1 = source lines are for procedure or function
     2 = source lines are for type or package body
  This variable influence how the script processes the first source line.
  If OBJTYPE=2, the script assumes the first line is like TYPE BODY <name>
  rather than like TYPE <name>.
-->
 <xsl:template match="SOURCE_LINES">
  <xsl:param name="OBJTYPE">0</xsl:param>
  <xsl:for-each select="SOURCE_LINES_ITEM">
   <xsl:choose>
    <xsl:when test="position()=1">
     <!-- process first line of source -->
     <xsl:choose>
      <!-- TYPE, PACKAGE -->
      <xsl:when test="$OBJTYPE=0">
       <!-- count tokens (THIS IS ERROR-PRONE) -->
       <xsl:value-of select="substring-after(substring-after(normalize-space(SOURCE),' '),' ')"/>
       <!-- If 'normalize-space' removed trailing LF, reinsert it -->
       <xsl:if test="substring(SOURCE,string-length(SOURCE),1)!=
            substring(normalize-space(SOURCE),
                         string-length(normalize-space(SOURCE)),1)">
        <xsl:text>&#xa;</xsl:text>
       </xsl:if>
      </xsl:when>
      <!-- PROCEDURE, FUNCTION -->
      <xsl:when test="$OBJTYPE=1">
       <xsl:choose>
        <!-- for procedures or functions with arg lists use open paren as delim -->
        <xsl:when test="contains(SOURCE,'(')">
         <xsl:text>(</xsl:text>
         <xsl:value-of select="substring-after(SOURCE,'(')"/>
        </xsl:when>
        <!-- otherwise count tokens (THIS IS ERROR-PRONE) -->
        <xsl:otherwise>
         <xsl:value-of select="substring-after(substring-after(normalize-space(SOURCE),' '),' ')"/>
         <!-- If 'normalize-space' removed trailing LF, reinsert it -->
         <xsl:if test="substring(SOURCE,string-length(SOURCE),1)!=
            substring(normalize-space(SOURCE),
                         string-length(normalize-space(SOURCE)),1)">
          <xsl:text>&#xa;</xsl:text>
         </xsl:if>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:when>
      <!-- TYPE/PACKAGE BODY -->
      <xsl:otherwise>
       <xsl:value-of select="substring-after(
         substring-after(
          substring-after(normalize-space(SOURCE),' '),' '),' ')"/>
       <!-- 'normalize' removed trailing LF, so reinsert it -->
       <xsl:text>&#xa;</xsl:text>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <!-- process lines 2-N of source -->
    <xsl:otherwise>
     <xsl:value-of select="SOURCE"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>
 <xsl:template name="DoSourceLines">
  <xsl:param name="SourceLines"/>
  <xsl:param name="SchemaNode" select="''"/>
  <xsl:param name="NameNode" select="''"/>
  <!-- Should we generate additional syntax to try to replay type version evolution?
       This is determined either by explicitly setting the PRESERVE_TYPE_EVOLUTION 
       transform parameter to 1 or implicitly by Data Pump (we know it is implicit if the value 
       is the same as the default value, 3, because passed-in-values should be just 0 or 1).
       If the PRESERVE_TYPE_EVOLUTION transform is set to 0, then we keep
       the source lines together as one big CREATE TYPE operation.  This option exists
       by default for non-Data Pump requests (like MDAPI's GET_DDL of a 'TYPE' object)
       and during Data Pump import when it retries the creating of a TYPE after an error. .-->
  <xsl:variable name="TypeEvolution">
   <xsl:choose>
    <xsl:when test="$PRESERVE_TYPE_EVOLUTION=1 or 
                    ($PRESERVE_TYPE_EVOLUTION=3 and $EXPORT=1)">1</xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:for-each select="$SourceLines/SOURCE_LINES_ITEM">
   <xsl:choose>
    <xsl:when test="PRE_NAME=1">
     <xsl:if test="NEW_VERSION and NEW_VERSION=1 and $TypeEvolution=1">
      <!-- If this line is the first new line from a new version of the 
          type, then insert the semicolon and LF before it.  This will
          cause the next lines, when executed, to be done so as a
          separate operation, which increments the type's version number. -->
      <xsl:text>; &#xa;</xsl:text>
      <xsl:call-template name="DoParse">
       <xsl:with-param name="Verb">ALTER</xsl:with-param>
       <xsl:with-param name="ObjectType">TYPE</xsl:with-param>
       <xsl:with-param name="SchemaNode" select="$SchemaNode"/>
       <xsl:with-param name="NameNode" select="$NameNode"/>
      </xsl:call-template>
     </xsl:if>
     <!-- Part of the early type evolution solution as well as used in parsing
         PROCEDURE/FUNCTION, etc, source lines.  Earier versions have no 
         POST_KEYW,  Skip lines prior to the name. -->
     <xsl:if test="POST_KEYW">
      <xsl:value-of select="substring(SOURCE,POST_KEYW)"/>
     </xsl:if>
    </xsl:when>
    <xsl:when test="POST_ATNAME_OFF and POST_ATNAME_OFF>0 and NEW_VERSION">
     <!-- We want the generated DDL to replay the type's version evolutoin AND the
         XML document involved includes the newest approach, represented by the
         existence of the NEW_VERSION element. -->
     <xsl:if test=" NEW_VERSION=1 and $TypeEvolution=1">
      <!-- If this line is the first new line from a new version of the 
          type, then insert the semicolon and LF before it.  This will
          cause the next lines, when executed, to be done so as a
          separate operation, which increments the type's version number. -->
      <xsl:text>; &#xa;</xsl:text>
      <xsl:call-template name="DoParse">
       <xsl:with-param name="Verb">ALTER</xsl:with-param>
       <xsl:with-param name="ObjectType">TYPE</xsl:with-param>
       <xsl:with-param name="SchemaNode" select="$SchemaNode"/>
       <xsl:with-param name="NameNode" select="$NameNode"/>
      </xsl:call-template>
     </xsl:if>
     <!--If this source line contains the type's name, then rebuild the source line by 
        sandwiching around the new schema-qualified-name all that comes before 
        and after the name on this line. -->
     <!-- Everything, if any, before the name -->
     <xsl:if test="ATNAME_OFF>0">
      <xsl:value-of select="substring(SOURCE,1,ATNAME_OFF)"/>
     </xsl:if>
     <!-- Replace name with the schema-qualified one -->
     <xsl:call-template name="QuoteObject">
      <xsl:with-param name="Schema" select="$SchemaNode"/>
      <xsl:with-param name="Object" select="$NameNode"/>
     </xsl:call-template>
     <xsl:text> </xsl:text>
     <!-- Append the rest of the line after the name -->
     <xsl:value-of select="substring(SOURCE,POST_ATNAME_OFF)"/>
    </xsl:when>
    <xsl:when test="POST_ATNAME_OFF and POST_ATNAME_OFF>0 and $TypeEvolution=1">
     <!-- Type evolution is requested, but we don't have the latest XML 
         document (missing the NEW_VERSION element), so resort back 
         to the previous, partial solution.  When the source line has a 
         positive POST_ATNAME_OFF value, add the semicolon/LF break before
         this line.  This solution assumes the 'alter' and 'type' keyword tokens
         exist on this same line as the type's name and blindly replaces everything
         before the type's name with  'ALTER TYPE' syntax.  (This effort
         fails to handle the case when ALTER and TYPE keywords are on 
         different lines preceding this line with the type's name).  Also 
         preface the type name with the schema name, but this is ultimately 
         controlled by the EMIT_SCHEMA transform parameter. -->
     <xsl:text>; &#xa;</xsl:text>
     <xsl:call-template name="DoParse">
      <xsl:with-param name="Verb">ALTER</xsl:with-param>
      <xsl:with-param name="ObjectType">TYPE</xsl:with-param>
      <xsl:with-param name="SchemaNode" select="$SchemaNode"/>
      <xsl:with-param name="NameNode" select="$NameNode"/>
     </xsl:call-template>
     <xsl:text>ALTER TYPE </xsl:text>
     <xsl:call-template name="QuoteObject">
      <xsl:with-param name="Schema" select="$SchemaNode"/>
      <xsl:with-param name="Object" select="$NameNode"/>
     </xsl:call-template>
     <xsl:text> </xsl:text>
     <xsl:value-of select="substring(SOURCE,POST_ATNAME_OFF)"/>
    </xsl:when>
    <xsl:when test="PRE_NAME=0 and POST_NAME_OFF=0">
     <xsl:choose>
      <xsl:when test="POST_KEYW">
       <xsl:value-of select="substring(SOURCE,POST_KEYW)"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:value-of select="SOURCE"/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <!-- Emit everything after the name.  2 cases:
        1. A procedure or function with arguments, e.g., f(a int).
        2. Something without a parenthesized list of arguments. -->
    <xsl:when test="POST_NAME_OFF>0">
     <xsl:if test="POST_KEYW">
      <xsl:value-of select="substring(SOURCE,POST_KEYW,PRE_NAME_LEN)"/>
     </xsl:if>
     <xsl:value-of select="substring(SOURCE,POST_NAME_OFF)"/>
    </xsl:when>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>
</xsl:stylesheet>

OHA YOOOO