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

<?xml version="1.0" encoding="utf-8"?>
<!--

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

NAME
    kustablc.xsl
DESCRIPTION
    Templates for common and utility functions used by both kustabld.xsl
    and kuatable.xsl

MODIFIED        MM/DD/YY
    jjanosik    04/04/17 - Bug 25786429: We only need one semi-colon to
                           terminate the create table
    jjanosik    12/22/16 - Bug 25260340: Support suplemental log in nested
                           tables
    rapayne     12/22/16 - Bug 22069676: fix VECTOR ENCODE col attribute
    jjanosik    07/22/16 - bug 23708351: Bypass partitioning if the table
                           is clustered
    tojhuan     07/20/16 - lrg 18954633: hide element IDs in XMLSCHEMA clauses
    tbhukya     05/13/16 - Bug 23248862: Generate result cache
                           irrespective of segment creation
    tbhukya     04/13/16 - Bug 23035574: Encryption in lob storage param
    jjanosik    01/25/16 - bug 19792856 - handle user created lob index
    tbhukya     09/03/15 - Bug 21760912: Support new encryption algorithms
    rapayne     06/06/15 - bug 21205467: generate EVALUATE USING clause.
    rapayne     01/25/15 - lrg 14979799: fix INDEXING attrib with DSC
    tbhukya     01/05/15 - Bug 20319428: Declare referred params
    lbarton     09/24/14 - row archival and SXML
    lbarton     06/05/14 - bug 18750140: valid-time temporal
    abodge      06/04/14 - CM MODIFIED: Gen datatype clause
    lbarton     02/06/14 - bug 17943479: make template name unique;
                           move Datatype to kuscommc
    lbarton     03/01/12 - 36954_dpump_tabcluster_zonemap
    rapayne     12/25/11 - proj 37634: Partial Index support.
    rapayne     11/08/11 - support ON NULL identity column qualifier
    rapayne     08/21/11 - project 36780: Identity Column support.
    rapayne     06/03/11 - bug 12613505: fix quoting for VARRAY properties.
    abodge      09/22/09 - CONSOLIDATE STYLESHEETS: TargetSchemaName
    ebatbout    12/12/08 - fix problem with TIME WITH TIMEZONE datatype in 
                           template, datatype   
    rapayne     11/15/08 - bug 7595899:fix number datatype when PRECISION has been 'deleted'.
    rapayne     10/07/08 - account for CHAR_SEMANTIC diffs
    lbarton     08/28/08 - xmltype virtual columns
    rapayne     07/15/08 - account for difdoc attributes before processing SECUREFILE lobs.
                           i.e., don't process if /sxml:SECUREFILE/@src=1
    lbarton     02/11/08 - reference/system partitioning
    rapayne     01/10/09 - Handle dif doc case in which both PCTVERSION
                                        are RETENTION are present.
    lbarton     02/02/08 - bug 6789892: fix alter number precision support.
    ebatbout    01/10/08 - bug 6568074: comment out encrypt/decrypt & support 
                           compress & deduplicates defaults in LobProperties
    rapayne     12/12/07 - Support CHAR_SEMANTICS
    lbarton     12/12/07 - bug 6682373: char semantics
    rapayne     12/07/07 - Bug 6677390: fix RETENTION processing for
                           basicfile lobs.
    slynn       02/25/07 - Backout changes that removed dedup validate.
    rapayne     02/08/07 - merge slynn removal of (A)SYNC and VALIDATE
    lbarton     09/28/06 - modify ENABLE, etc. to exclude src=1
    lbarton     05/25/06 - 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="kuscommc.xsl"/>
 <!-- Top level params -->
 <xsl:param name="PARTITIONING">1</xsl:param>
 <xsl:param name="TABLESPACE">1</xsl:param>
 <!-- CM template to generate a standalone
      datatype clause from a subtree headed by COL_LIST_ITEM 
 -->
 <xsl:template match="sxml:COL_LIST_ITEM">
  <xsl:call-template name="Datatype">
  </xsl:call-template>
 </xsl:template>
 <!-- Templates -->
 <xsl:template match="sxml:CHAR_SEMANTICS">
  <!-- *******************************************************************
Template: CHAR_SEMANTICS
Current node: CHAR_SEMANTICS
******************************************************************** -->
  <!-- If we are processing a diff doc and char_semantics have been removed (i.e., src=1) then simply omit and the byte semantic default will be applied
-->
  <xsl:if test="not(./@src='1')">
   <xsl:text> CHAR</xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:VIRTUAL">
  <!-- *******************************************************************
Template: VIRTUAL
Current node: VIRTUAL
******************************************************************** -->
  <xsl:text> GENERATED ALWAYS AS (</xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>) VIRTUAL</xsl:text>
 </xsl:template>
 <xsl:template name="doSeqOptions">
  <xsl:param name="seqNode"/>
  <!-- *******************************************************************
Template: doSeqOptions
Parameters:
  seqNode   <SEQUENCE | IDENTITY_COLUMN>
******************************************************************** -->
  <xsl:if test="$seqNode/sxml:MINVALUE">
   <xsl:text> MINVALUE </xsl:text>
   <xsl:value-of select="$seqNode/sxml:MINVALUE"/>
  </xsl:if>
  <xsl:if test="$seqNode/sxml:MAXVALUE">
   <xsl:text> MAXVALUE </xsl:text>
   <xsl:value-of select="$seqNode/sxml:MAXVALUE"/>
  </xsl:if>
  <xsl:if test="$seqNode/sxml:INCREMENT">
   <xsl:text> INCREMENT BY </xsl:text>
   <xsl:value-of select="$seqNode/sxml:INCREMENT"/>
  </xsl:if>
  <xsl:if test="$seqNode/sxml:START_WITH">
   <xsl:text> START WITH </xsl:text>
   <xsl:value-of select="$seqNode/sxml:START_WITH"/>
  </xsl:if>
  <xsl:if test="$seqNode/sxml:CACHE">
   <xsl:choose>
    <xsl:when test="$seqNode/sxml:CACHE=0">
     <xsl:text> NOCACHE</xsl:text>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text> CACHE </xsl:text>
     <xsl:value-of select="$seqNode/sxml:CACHE"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
  <xsl:choose>
   <xsl:when test="$seqNode/sxml:ORDER">
    <xsl:text> ORDER</xsl:text>
   </xsl:when>
   <xsl:otherwise>
    <xsl:text> NOORDER</xsl:text>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:choose>
   <xsl:when test="$seqNode/sxml:CYCLE">
    <xsl:text> CYCLE</xsl:text>
   </xsl:when>
   <xsl:otherwise>
    <xsl:text> NOCYCLE</xsl:text>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:IDENTITY_COLUMN">
  <!-- *******************************************************************
Template: IDENTITY_COLUMN
Current node: IDENTITY_COLUMN
******************************************************************** -->
  <xsl:text> GENERATED </xsl:text>
  <xsl:choose>
   <xsl:when test="sxml:GENERATION = 'DEFAULT'">
    <xsl:text>BY DEFAULT</xsl:text>
    <xsl:if test="sxml:ON_NULL">
     <xsl:text> ON NULL</xsl:text>
    </xsl:if>
   </xsl:when>
   <xsl:otherwise>
    <xsl:text>ALWAYS</xsl:text>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:text> AS IDENTITY</xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:call-template name="doSeqOptions">
   <xsl:with-param name="seqNode" select="."/>
  </xsl:call-template>
 </xsl:template>
 <xsl:template match="sxml:HIDDEN">
  <!-- *******************************************************************
Template: HIDDEN
Current node: HIDDEN
******************************************************************** -->
  <xsl:text> HIDDEN</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:EVALUATE">
  <!-- *******************************************************************
Template: EVALUATE
Current node: EVALUATE
******************************************************************** -->
  <xsl:text> EVALUATE USING </xsl:text>
  <xsl:value-of select="."/>
 </xsl:template>
 <xsl:template match="sxml:DEFAULT">
  <!-- *******************************************************************
Template: DEFAULT
Current node: DEFAULT
******************************************************************** -->
  <xsl:text> DEFAULT </xsl:text>
  <xsl:value-of select="."/>
 </xsl:template>
 <xsl:template match="sxml:DEFAULT_ON_NULL">
  <!-- *******************************************************************
Template: DEFAULT_ON_NULL
Current node: DEFAULT_ON_NULL
******************************************************************** -->
  <xsl:text> DEFAULT ON NULL </xsl:text>
  <xsl:value-of select="."/>
 </xsl:template>
 <xsl:template match="sxml:VECTOR_ENCODE">
  <!-- *******************************************************************
Template: VECTOR_ENCODE
Current node: VECTOR_ENCODE
******************************************************************** -->
  <xsl:text> VECTOR ENCODE</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:ENCRYPT | sxml:LOBENCRYPT">
  <!-- *******************************************************************
Template: ENCRYPT | LOBENCRYPT
Current node: ENCRYPT | LOBENCRYPT
******************************************************************** -->
  <xsl:text> ENCRYPT USING </xsl:text>
  <xsl:value-of select="sxml:USING"/>
  <xsl:if test="sxml:NOSALT">
   <xsl:text> NO SALT</xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:TABLE_PROPERTIES">
  <xsl:param name="IsClustered">0</xsl:param>
  <!-- *******************************************************************
Template: TABLE_PROPERTIES
Parameters:
  IsClustered - defaulted to 0 (false) - is the table clustered
******************************************************************** -->
  <!-- if table is partitioned, default physical properties should
      precede column properties -->
  <xsl:choose>
   <xsl:when test="$STATISTICS=1">
    <xsl:if test="$IsClustered=0">
     <xsl:apply-templates select="sxml:RANGE_PARTITIONING/sxml:PARTITION_LIST"/>
     <xsl:apply-templates select="sxml:LIST_PARTITIONING/sxml:PARTITION_LIST"/>
     <xsl:apply-templates select="sxml:HASH_PARTITIONING/sxml:PARTITION_LIST"/>
    </xsl:if>
   </xsl:when>
   <xsl:otherwise>
    <xsl:if test="$IsClustered=0">
     <xsl:apply-templates select="sxml:RANGE_PARTITIONING/sxml:DEFAULT_PHYSICAL_PROPERTIES"/>
     <xsl:apply-templates select="sxml:HASH_PARTITIONING/sxml:DEFAULT_PHYSICAL_PROPERTIES"/>
     <xsl:apply-templates select="sxml:LIST_PARTITIONING/sxml:DEFAULT_PHYSICAL_PROPERTIES"/>
     <xsl:apply-templates select="sxml:SYSTEM_PARTITIONING/sxml:DEFAULT_PHYSICAL_PROPERTIES"/>
     <xsl:apply-templates select="sxml:REFERENCE_PARTITIONING/sxml:DEFAULT_PHYSICAL_PROPERTIES"/>
    </xsl:if>
    <!-- Process default table level indexing attribute:
        note: the <INDEXING> element will only be present if it is different
                 then the default (i.e., it has been disabled)
    -->
    <xsl:if test="sxml:INDEXING">
     <xsl:text> INDEXING </xsl:text>
     <xsl:value-of select="sxml:INDEXING"/>
    </xsl:if>
    <xsl:apply-templates select="sxml:COLUMN_PROPERTIES"/>
    <xsl:apply-templates select="sxml:XMLTYPE_VIRTUAL_COLUMNS"/>
    <xsl:apply-templates select="sxml:CLUSTERING">
     <xsl:with-param name="ParentNode" select="../.."/>
    </xsl:apply-templates>
    <xsl:if test="$PARTITIONING=1 and $IsClustered=0">
     <xsl:if test="sxml:RANGE_PARTITIONING">
      <xsl:call-template name="TableRangePartitioning">
       <xsl:with-param name="PartitioningNode" select="sxml:RANGE_PARTITIONING"/>
      </xsl:call-template>
     </xsl:if>
     <xsl:if test="sxml:LIST_PARTITIONING">
      <xsl:call-template name="TableListPartitioning">
       <xsl:with-param name="PartitioningNode" select="sxml:LIST_PARTITIONING"/>
      </xsl:call-template>
     </xsl:if>
     <xsl:if test="sxml:HASH_PARTITIONING">
      <xsl:call-template name="TableHashPartitioning">
       <xsl:with-param name="PartitioningNode" select="sxml:HASH_PARTITIONING"/>
      </xsl:call-template>
     </xsl:if>
     <xsl:if test="sxml:REFERENCE_PARTITIONING">
      <xsl:call-template name="TableReferencePartitioning">
       <xsl:with-param name="PartitioningNode" select="sxml:REFERENCE_PARTITIONING"/>
      </xsl:call-template>
     </xsl:if>
     <xsl:if test="sxml:SYSTEM_PARTITIONING">
      <xsl:call-template name="TableSystemPartitioning">
       <xsl:with-param name="PartitioningNode" select="sxml:SYSTEM_PARTITIONING"/>
      </xsl:call-template>
     </xsl:if>
    </xsl:if>
    <!-- cache -->
    <xsl:if test="sxml:CACHE"> CACHE</xsl:if>
    <!-- Result_cache -->
    <xsl:if test="sxml:RESULT_CACHE='FORCE'"> RESULT_CACHE(MODE FORCE)</xsl:if>
    <xsl:if test="sxml:RESULT_CACHE='MANUAL'"> RESULT_CACHE(MODE MANUAL)</xsl:if>
    <!-- parallel -->
    <xsl:apply-templates select="sxml:PARALLEL"/>
    <!-- row dependencies -->
    <xsl:if test="sxml:ROW_DEPENDENCIES"> ROWDEPENDENCIES</xsl:if>
    <!-- row movement -->
    <xsl:if test="sxml:ROW_MOVEMENT"> ENABLE ROW MOVEMENT</xsl:if>
    <xsl:apply-templates select="sxml:FLASHBACK_ARCHIVE"/>
    <xsl:apply-templates select="sxml:ROW_ARCHIVAL"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:COLUMN_PROPERTIES">
  <xsl:param name="PartitionType" select="''"/>
  <xsl:param name="Subpartition">0</xsl:param>
  <!-- *******************************************************************
Template: COLUMN_PROPERTIES
 PartitionType - RANGE, HASH, LIST or ''
 Subpartition  1 = this is a subpartition (0 = it isn't)
******************************************************************** -->
  <xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM">
   <xsl:choose>
    <xsl:when test="sxml:DATATYPE='UDT'">
     <xsl:call-template name="SubstitutableColProperties">
      <xsl:with-param name="ColListItem" select="."/>
     </xsl:call-template>
    </xsl:when>
    <xsl:when test="sxml:DATATYPE='NESTED_TABLE'">
     <xsl:call-template name="NestedTableColProperties">
      <xsl:with-param name="ColNameNode" select="sxml:NAME"/>
      <xsl:with-param name="ColProperties" select="../.."/>
     </xsl:call-template>
    </xsl:when>
    <xsl:when test="sxml:DATATYPE='VARRAY'">
     <xsl:call-template name="VarrayColProperties">
      <xsl:with-param name="ColNameNode" select="sxml:NAME"/>
      <xsl:with-param name="ColProperties" select="../.."/>
     </xsl:call-template>
    </xsl:when>
    <xsl:when test="sxml:DATATYPE='OPAQUE'">
     <!-- yucky complexity -->
     <xsl:choose>
      <xsl:when test="local-name(../../..)='PARTITION_LIST_ITEM'">
       <xsl:call-template name="LobColProperties">
        <xsl:with-param name="ColListItem" select="."/>
        <xsl:with-param name="DataType" select="sxml:DATATYPE"/>
        <xsl:with-param name="PartitionType" select="$PartitionType"/>
       </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
       <xsl:call-template name="OpaqueColProperties">
        <xsl:with-param name="ColNameNode" select="sxml:NAME"/>
        <xsl:with-param name="ColProperties" select="../.."/>
       </xsl:call-template>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <xsl:when test="sxml:DATATYPE='CLOB' or
                   sxml:DATATYPE='BLOB' or
                   sxml:DATATYPE='NCLOB'">
     <xsl:call-template name="LobColProperties">
      <xsl:with-param name="ColListItem" select="."/>
      <xsl:with-param name="DataType" select="sxml:DATATYPE"/>
      <xsl:with-param name="PartitionType" select="$PartitionType"/>
      <xsl:with-param name="Subpartition" select="$Subpartition"/>
     </xsl:call-template>
    </xsl:when>
    <xsl:when test="sxml:DATATYPE='XMLTYPE'">
     <xsl:call-template name="XMLTypeColProperties">
      <xsl:with-param name="ColNameNode" select="sxml:NAME"/>
      <xsl:with-param name="ColProperties" select="../.."/>
     </xsl:call-template>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text>
 **** ERROR: kustabld.xsl UNRECOGNIZED COLUMN PROPERTIES: name = </xsl:text>
     <xsl:value-of select="sxml:NAME"/>
     <xsl:text> datatype = </xsl:text>
     <xsl:value-of select="sxml:DATATYPE"/>
     <xsl:text> ****
</xsl:text>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>
 <xsl:template match="sxml:FLASHBACK_ARCHIVE">
  <!-- *******************************************************************
Template: FLASHBACK_ARCHIVE
******************************************************************** -->
  <xsl:text> FLASHBACK ARCHIVE "</xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>"</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:ROW_ARCHIVAL">
  <!-- *******************************************************************
Template: ROW_ARCHIVAL
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa; </xsl:text>
  </xsl:if>
  <xsl:text> ROW ARCHIVAL </xsl:text>
 </xsl:template>
 <xsl:template name="SubstitutableColProperties">
  <xsl:param name="ColListItem" select="''"/>
  <!-- *******************************************************************
Template: SubstitutableColProperties
Parameters:
 ColListItem: TABLE/TABLE_PROPERTIES/COLUMN_PROPERTIES/COL_LIST/COL_LIST_ITEM
******************************************************************** -->
  <xsl:if test="$ColListItem/sxml:OF_TYPE or $ColListItem/sxml:SUBSTITUTABLE">
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa;</xsl:text>
   </xsl:if>
   <xsl:text> COLUMN </xsl:text>
   <xsl:call-template name="QuotedName">
    <xsl:with-param name="NameNode" select="$ColListItem/sxml:NAME"/>
   </xsl:call-template>
   <xsl:apply-templates select="$ColListItem/sxml:OF_TYPE"/>
   <xsl:apply-templates select="$ColListItem/sxml:SUBSTITUTABLE"/>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:OF_TYPE">
  <!-- *******************************************************************
Template: OF_TYPE
******************************************************************** -->
  <xsl:text> IS OF TYPE (ONLY </xsl:text>
  <xsl:value-of select="."/>
  <xsl:text>)</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:SUBSTITUTABLE">
  <!-- *******************************************************************
Template: SUBSTITUTABLE
******************************************************************** -->
  <xsl:if test=".='N'"> NOT</xsl:if>
  <xsl:text> SUBSTITUTABLE AT ALL LEVELS</xsl:text>
 </xsl:template>
 <xsl:template name="NestedTableColProperties">
  <xsl:param name="ColNameNode" select="''"/>
  <xsl:param name="ColProperties" select="''"/>
  <!-- *******************************************************************
Template: NestedTableColProperties
Parameters:
 ColNameNode   - column name
 ColProperties - TABLE_PROPERTIES/COLUMN_PROPERTIES
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:text> NESTED TABLE </xsl:text>
  <xsl:choose>
   <xsl:when test="$ColNameNode='COLUMN_VALUE'">COLUMN_VALUE</xsl:when>
   <xsl:otherwise>
    <xsl:call-template name="QuotedName">
     <xsl:with-param name="NameNode" select="$ColNameNode"/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:apply-templates select="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:NESTED_TABLE_PROPERTIES"/>
 </xsl:template>
 <xsl:template match="sxml:NESTED_TABLE_PROPERTIES">
  <!-- *******************************************************************
Template: NESTED_TABLE_PROPERTIES
******************************************************************** -->
  <xsl:text> STORE AS </xsl:text>
  <xsl:call-template name="QuotedName">
   <xsl:with-param name="NameNode" select="sxml:STORAGE_TABLE/sxml:NAME"/>
  </xsl:call-template>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:if test="(sxml:STORAGE_TABLE/sxml:PRIMARY_KEY_CONSTRAINT_LIST or
                       sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES//sxml:SEGMENT_ATTRIBUTES or
                       sxml:STORAGE_TABLE/sxml:TABLE_PROPERTIES)
                       and $SEGMENT_ATTRIBUTES!=0">
   <xsl:text> (</xsl:text>
   <xsl:if test="sxml:STORAGE_TABLE/sxml:PRIMARY_KEY_CONSTRAINT_LIST">
    <xsl:text> (</xsl:text>
    <xsl:call-template name="Constraints">
     <xsl:with-param name="ParentNode" select="sxml:STORAGE_TABLE"/>
     <xsl:with-param name="IOT">
      <xsl:choose>
       <xsl:when test="sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES/sxml:INDEX_ORGANIZED_TABLE">1</xsl:when>
       <xsl:otherwise>0</xsl:otherwise>
      </xsl:choose>
     </xsl:with-param>
    </xsl:call-template>
    <xsl:text>)</xsl:text>
    <xsl:if test="$PRETTY=1">
     <xsl:text>&#xa;</xsl:text>
    </xsl:if>
   </xsl:if>
   <!-- supplemental logging -->
   <xsl:if test="sxml:STORAGE_TABLE/sxml:SUPPLEMENTAL_LOGGING">
    <xsl:text>(</xsl:text>
     <xsl:apply-templates select="sxml:STORAGE_TABLE/sxml:SUPPLEMENTAL_LOGGING"/>
    <xsl:text>)</xsl:text>
   </xsl:if>
   <xsl:apply-templates select="sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES">
    <xsl:with-param name="DoCompress">N</xsl:with-param>
   </xsl:apply-templates>
   <xsl:apply-templates select="sxml:STORAGE_TABLE/sxml:TABLE_PROPERTIES">
    <xsl:with-param name="IsClustered">
     <xsl:choose>
      <xsl:when test="not (sxml:PHYSICAL_PROPERTIES)">0</xsl:when>
      <xsl:when test="sxml:PHYSICAL_PROPERTIES/sxml:CLUSTER_TABLE">1</xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
     </xsl:choose>
    </xsl:with-param>
   </xsl:apply-templates>
   <xsl:text> )</xsl:text>
  </xsl:if>
  <xsl:apply-templates select="sxml:RETURN_AS"/>
 </xsl:template>
 <xsl:template name="VarrayColProperties">
  <xsl:param name="ColNameNode" select="''"/>
  <xsl:param name="ColProperties" select="''"/>
  <!-- *******************************************************************
Template: VarrayColProperties
Parameters:
 ColNameNode   - column name
 ColProperties - TABLE_PROPERTIES/COLUMN_PROPERTIES
******************************************************************** -->
  <xsl:if test="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/*/sxml:STORAGE_TABLE/sxml:NAME or
             (($ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:TABLESPACE or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE_IN_ROW or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CHUNK or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:PCTVERSION or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CACHE or
                $ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES/sxml:NESTED_TABLE_PROPERTIES/sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES)
                and $SEGMENT_ATTRIBUTES!=0)">
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa;</xsl:text>
   </xsl:if>
   <xsl:text> VARRAY </xsl:text>
   <xsl:call-template name="QuotedName">
    <xsl:with-param name="NameNode" select="$ColNameNode"/>
   </xsl:call-template>
   <xsl:apply-templates select="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:VARRAY_PROPERTIES"/>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:VARRAY_PROPERTIES">
  <!-- *******************************************************************
Template: VARRAY_PROPERTIES
******************************************************************** -->
  <xsl:text> STORE AS </xsl:text>
  <xsl:choose>
   <xsl:when test="sxml:STORE_AS='TABLE'">
    <xsl:text>TABLE </xsl:text>
    <xsl:if test="sxml:NESTED_TABLE_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME">
     <xsl:call-template name="QuotedName">
      <xsl:with-param name="NameNode" select="sxml:NESTED_TABLE_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME"/>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="sxml:NESTED_TABLE_PROPERTIES/sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES and $SEGMENT_ATTRIBUTES!=0">
     <xsl:if test="$PRETTY=1">
      <xsl:text>&#xa;</xsl:text>
     </xsl:if>
     <xsl:text> (</xsl:text>
     <xsl:apply-templates select="sxml:NESTED_TABLE_PROPERTIES/sxml:STORAGE_TABLE/sxml:PHYSICAL_PROPERTIES"/>
     <xsl:text>)</xsl:text>
    </xsl:if>
    <xsl:apply-templates select="sxml:NESTED_TABLE_PROPERTIES/sxml:RETURN_AS"/>
   </xsl:when>
   <xsl:otherwise>
    <!-- store as LOB -->
    <xsl:if test="$VERSION>=1100000000">
     <xsl:choose>
      <xsl:when test="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE">
       <xsl:text>SECUREFILE </xsl:text>
      </xsl:when>
      <xsl:otherwise>
       <xsl:text>BASICFILE </xsl:text>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:if>
    <xsl:text>LOB </xsl:text>
    <xsl:if test="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME">
     <xsl:call-template name="QuotedName">
      <xsl:with-param name="NameNode" select="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME"/>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="(sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:TABLESPACE or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE_IN_ROW or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CHUNK or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:PCTVERSION or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:RETENTION or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CACHE or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:LOBENCRYPT or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:LOBCOMPRESS or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:DEDUPLICATE or
                sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:VALIDATE)
                and $SEGMENT_ATTRIBUTES!=0">
     <xsl:if test="$PRETTY=1">
      <xsl:text>&#xa;</xsl:text>
     </xsl:if>
     <xsl:text> (</xsl:text>
     <xsl:call-template name="LobProperties">
      <xsl:with-param name="StorageTable" select="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE"/>
     </xsl:call-template>
     <xsl:text>)</xsl:text>
    </xsl:if>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 <xsl:template name="OpaqueColProperties">
  <xsl:param name="ColNameNode" select="''"/>
  <xsl:param name="ColProperties" select="''"/>
  <!-- *******************************************************************
Template: OpaqueColProperties
Current node: TABLE/TABLE_PROPERTIES/COLUMN_PROPERTIES/COL_LIST/COL_LIST_ITEM
Parameters:
 ColNameNode   - column name
 ColProperties - TABLE_PROPERTIES/COLUMN_PROPERTIES
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:text> OPAQUE TYPE </xsl:text>
  <xsl:call-template name="QuotedName">
   <xsl:with-param name="NameNode" select="$ColNameNode"/>
  </xsl:call-template>
  <xsl:text> STORE AS </xsl:text>
  <xsl:if test="$VERSION>=1100000000">
   <xsl:choose>
    <xsl:when test="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE">
     <xsl:text>SECUREFILE </xsl:text>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text>BASICFILE </xsl:text>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
  <xsl:text> LOB </xsl:text>
  <xsl:if test="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME">
   <xsl:call-template name="QuotedName">
    <xsl:with-param name="NameNode" select="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME"/>
   </xsl:call-template>
  </xsl:if>
  <xsl:text> (</xsl:text>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa; </xsl:text>
  </xsl:if>
  <xsl:call-template name="LobProperties">
   <xsl:with-param name="StorageTable" select="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE"/>
  </xsl:call-template>
  <xsl:text>)</xsl:text>
 </xsl:template>
 <xsl:template name="LobColProperties">
  <xsl:param name="ColListItem" select="''"/>
  <xsl:param name="DataType" select="''"/>
  <xsl:param name="PartitionType" select="''"/>
  <xsl:param name="Subpartition">0</xsl:param>
  <xsl:param name="ModifyLobStorage">0</xsl:param>
  <!-- *******************************************************************
Template: LobColProperties
Parameters:
 ColListItem: TABLE/TABLE_PROPERTIES/COLUMN_PROPERTIES/COL_LIST/COL_LIST_ITEM
 DataType
 PartitionType - RANGE, HASH, LIST or ''
 Subpartition  1 = this is a subpartition (0 = it isn't)
 ModifyLobStorage - 1 = generating ALTER TABLE MODIFY LOB
******************************************************************** -->
  <xsl:if test="($ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:TABLESPACE or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE_IN_ROW or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CHUNK or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:PCTVERSION or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:RETENTION or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:STORAGE or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:CACHE or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:LOBENCRYPT or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:LOBCOMPRESS or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:DEDUPLICATE or
                $ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:VALIDATE)
                and $SEGMENT_ATTRIBUTES!=0">
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa;</xsl:text>
   </xsl:if>
   <xsl:text> LOB (</xsl:text>
   <xsl:call-template name="QuotedName">
    <xsl:with-param name="NameNode" select="$ColListItem/sxml:NAME"/>
   </xsl:call-template>
   <xsl:text>)</xsl:text>
   <xsl:text> STORE AS </xsl:text>
   <xsl:if test="$VERSION>=1100000000">
    <xsl:choose>
     <xsl:when test="$ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE">
      <xsl:text>SECUREFILE </xsl:text>
     </xsl:when>
     <xsl:otherwise>
      <xsl:text>BASICFILE </xsl:text>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:if>
   <xsl:if test="$ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME">
    <xsl:call-template name="QuotedName">
     <xsl:with-param name="NameNode" select="$ColListItem/sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME"/>
    </xsl:call-template>
   </xsl:if>
   <xsl:apply-templates select="$ColListItem/sxml:LOB_PROPERTIES">
    <xsl:with-param name="DataType" select="$DataType"/>
    <xsl:with-param name="PartitionType" select="$PartitionType"/>
    <xsl:with-param name="Subpartition" select="$Subpartition"/>
    <xsl:with-param name="ModifyLobStorage" select="$ModifyLobStorage"/>
   </xsl:apply-templates>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:LOB_PROPERTIES">
  <xsl:param name="DataType" select="''"/>
  <xsl:param name="PartitionType" select="''"/>
  <xsl:param name="Subpartition">0</xsl:param>
  <xsl:param name="ModifyLobStorage">0</xsl:param>
  <!-- *******************************************************************
Template: LOB_PROPERTIES
 DataType
 PartitionType - RANGE, HASH, LIST or ''
 Subpartition  1 = this is a subpartition (0 = it isn't)
 ModifyLobStorage - 1 = generating ALTER TABLE MODIFY LOB
******************************************************************** -->
  <xsl:if test="((sxml:STORAGE_TABLE/sxml:TABLESPACE 
                and $TABLESPACE!=0) or
                sxml:STORAGE_TABLE/sxml:STORAGE_IN_ROW or
                sxml:STORAGE_TABLE/sxml:CHUNK or
                sxml:STORAGE_TABLE/sxml:PCTVERSION or
                sxml:STORAGE_TABLE/sxml:RETENTION or
                sxml:STORAGE_TABLE/sxml:STORAGE or
                sxml:STORAGE_TABLE/sxml:CACHE or
                sxml:STORAGE_TABLE/sxml:LOBENCRYPT or
                sxml:STORAGE_TABLE/sxml:LOBCOMPRESS or
                sxml:STORAGE_TABLE/sxml:DEDUPLICATE or
                sxml:STORAGE_TABLE/sxml:VALIDATE)
                and $SEGMENT_ATTRIBUTES!=0">
   <xsl:text> (</xsl:text>
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa; </xsl:text>
   </xsl:if>
   <!-- mystery: why doesn't mdapi specify tablespace for varray store as lob?
     -->
   <xsl:choose>
    <!-- tablespace name not needed for opaques and anydata types
         except for hash partitioned table at partition level -->
    <xsl:when test="$DataType='OPAQUE' and $PartitionType!='HASH'"/>
    <xsl:otherwise>
     <xsl:if test="$TABLESPACE!=0 and $ModifyLobStorage=0">
      <xsl:apply-templates select="sxml:STORAGE_TABLE/sxml:TABLESPACE"/>
     </xsl:if>
    </xsl:otherwise>
   </xsl:choose>
   <!-- for subpartitions and hash partitions only TABLESPACE is valid -->
   <xsl:if test="$PartitionType!='HASH' and $Subpartition='0'">
    <xsl:call-template name="LobProperties">
     <xsl:with-param name="StorageTable" select="sxml:STORAGE_TABLE"/>
     <xsl:with-param name="ModifyLobStorage" select="$ModifyLobStorage"/>
    </xsl:call-template>
   </xsl:if>
   <xsl:if test="sxml:LOBINDEX">
    <xsl:apply-templates select="sxml:LOBINDEX"/>
   </xsl:if>
   <xsl:text>)</xsl:text>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:LOBINDEX">
  <!-- *******************************************************************
Template: LOBINDEX
ParentNode: LOB_PROPERTIES
Current Node: LOBINDEX
  Emits an INDEX clause in LOB definition in the CREATE TABLE if the
  user specified the LOB index
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:text>  INDEX </xsl:text>
  <xsl:call-template name="QuotedName">
   <xsl:with-param name="NameNode" select="sxml:NAME"/>
  </xsl:call-template>
  <xsl:text>(</xsl:text>
  <xsl:text> INITRANS </xsl:text>
  <xsl:value-of select="sxml:INITRANS"/>
  <xsl:text> MAXTRANS </xsl:text>
  <xsl:value-of select="sxml:MAXTRANS"/>
  <xsl:apply-templates select="sxml:STORAGE"/>
  <xsl:text>) </xsl:text>
 </xsl:template>
 <xsl:template name="XMLTypeColProperties">
  <xsl:param name="ColNameNode" select="''"/>
  <xsl:param name="ColProperties" select="''"/>
  <!-- *******************************************************************
Template: XMLTypeColProperties
Current node: TABLE/TABLE_PROPERTIES/COLUMN_PROPERTIES/COL_LIST/COL_LIST_ITEM
Parameters:
 ColNameNode   - column name
 ColProperties - TABLE_PROPERTIES/COLUMN_PROPERTIES
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:text> XMLTYPE COLUMN </xsl:text>
  <xsl:call-template name="QuotedName">
   <xsl:with-param name="NameNode" select="$ColNameNode"/>
  </xsl:call-template>
  <xsl:text> </xsl:text>
  <xsl:apply-templates select="$ColProperties/sxml:COL_LIST/sxml:COL_LIST_ITEM[sxml:NAME=$ColNameNode]/sxml:XMLTYPE_PROPERTIES"/>
 </xsl:template>
 <xsl:template match="sxml:XMLTYPE_PROPERTIES">
  <!-- *******************************************************************
Template: XMLTYPE_PROPERTIES
******************************************************************** -->
  <xsl:apply-templates select="sxml:XMLTYPE_STORAGE"/>
  <xsl:apply-templates select="sxml:XMLSCHEMA"/>
  <xsl:apply-templates select="sxml:ELEMENT"/>
  <xsl:call-template name="XMLTypeAllowDisallowDDL"/>
 </xsl:template>
 <xsl:template match="sxml:XMLTYPE_STORAGE">
  <!-- *******************************************************************
Template: XMLTYPE_STORAGE
******************************************************************** -->
  <xsl:choose>
   <xsl:when test="sxml:STORE_AS='LOB' or sxml:STORE_AS='BINARY_XML'">
    <xsl:text> STORE AS </xsl:text>
    <xsl:if test="$VERSION>=1100000000">
     <xsl:choose>
      <xsl:when test="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:SECUREFILE">
       <xsl:text>SECUREFILE </xsl:text>
      </xsl:when>
      <xsl:otherwise>
       <xsl:text>BASICFILE </xsl:text>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:if>
    <xsl:choose>
     <xsl:when test="sxml:STORE_AS='LOB'">CLOB </xsl:when>
     <xsl:when test="sxml:STORE_AS='BINARY_XML'">BINARY XML </xsl:when>
    </xsl:choose>
    <xsl:if test="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME">
     <xsl:call-template name="QuotedName">
      <xsl:with-param name="NameNode" select="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:NAME"/>
     </xsl:call-template>
    </xsl:if>
    <xsl:text> (</xsl:text>
    <xsl:if test="$PRETTY=1">
     <xsl:text>&#xa; </xsl:text>
    </xsl:if>
    <xsl:apply-templates select="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE/sxml:TABLESPACE"/>
    <xsl:call-template name="LobProperties">
     <xsl:with-param name="StorageTable" select="sxml:LOB_PROPERTIES/sxml:STORAGE_TABLE"/>
    </xsl:call-template>
    <xsl:text>)</xsl:text>
   </xsl:when>
   <xsl:when test="sxml:STORE_AS='OBJECT_RELATIONAL'">
    <!--xsl:text> STORE AS OBJECT RELATIONAL</xsl:text-->
   </xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template name="XMLTypeAllowDisallowDDL">
  <!-- *******************************************************************
Template: XMLTypeAllowDisallowDDL
Current Node: XMLTYPE_PROPERTIES
******************************************************************** -->
  <xsl:if test="sxml:XMLTYPE_STORAGE/sxml:STORE_AS='BINARY_XML'">
   <xsl:choose>
    <xsl:when test="sxml:DISALLOW_NONSCHEMA"> DISALLOW NONSCHEMA</xsl:when>
    <xsl:otherwise> ALLOW NONSCHEMA</xsl:otherwise>
   </xsl:choose>
   <xsl:choose>
    <xsl:when test="sxml:ALLOW_ANYSCHEMA"> ALLOW ANYSCHEMA</xsl:when>
    <xsl:otherwise> DISALLOW ANYSCHEMA</xsl:otherwise>
   </xsl:choose>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:XMLTYPE_VIRTUAL_COLUMNS">
  <!-- *******************************************************************
Template: XMLTYPE_VIRTUAL_COLUMNS
******************************************************************** -->
  <xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM">
   <xsl:if test="position()=1">
    <xsl:if test="$PRETTY=1">
     <xsl:text>&#xa;</xsl:text>
    </xsl:if>
    <xsl:text> VIRTUAL COLUMNS (</xsl:text>
   </xsl:if>
   <xsl:call-template name="QuotedName">
    <xsl:with-param name="NameNode" select="sxml:NAME"/>
   </xsl:call-template>
   <xsl:text> AS (</xsl:text>
   <xsl:value-of select="sxml:VIRTUAL"/>
   <xsl:text>)</xsl:text>
   <xsl:choose>
    <xsl:when test="position()!=last()">
     <xsl:text>,</xsl:text>
     <xsl:if test="$PRETTY=1">
      <xsl:text>&#xa;</xsl:text>
     </xsl:if>
    </xsl:when>
    <xsl:otherwise>)</xsl:otherwise>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>
 <xsl:template match="sxml:CLUSTERING">
  <xsl:param name="ParentNode" select="''"/>
  <!-- *******************************************************************
Template: CLUSTERING
Parameters:
  ParentNode - parent of schema/name
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:text> CLUSTERING </xsl:text>
  <xsl:if test="sxml:JOIN_CLAUSE_LIST and not(sxml:JOIN_CLAUSE_LIST/@src='1')">
   <xsl:apply-templates select="sxml:JOIN_CLAUSE_LIST">
    <xsl:with-param name="ParentNode" select="$ParentNode"/>
   </xsl:apply-templates>
  </xsl:if>
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:apply-templates select="sxml:ORDER"/>
  <xsl:choose>
   <xsl:when test="sxml:ON_LOAD and not(sxml:ON_LOAD/@src='1')"> YES </xsl:when>
   <xsl:otherwise> NO </xsl:otherwise>
  </xsl:choose>
  <xsl:text>ON LOAD </xsl:text>
  <xsl:choose>
   <xsl:when test="sxml:ON_DATA_MOVEMENT and not(sxml:ON_DATA_MOVEMENT/@src='1')"> YES </xsl:when>
   <xsl:otherwise> NO </xsl:otherwise>
  </xsl:choose>
  <xsl:text>ON DATA MOVEMENT </xsl:text>
  <xsl:call-template name="DoZonemapSxD"/>
 </xsl:template>
 <xsl:template match="sxml:JOIN_CLAUSE_LIST">
  <xsl:param name="ParentNode" select="''"/>
  <!-- *******************************************************************
Template: JOIN_CLAUSE_LIST
Parameters:
  ParentNode - parent of table schema/name
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:call-template name="SchemaName">
   <xsl:with-param name="ParentNode" select="$ParentNode"/>
  </xsl:call-template>
  <xsl:for-each select="sxml:JOIN_CLAUSE[not(@src='1')]">
   <xsl:text> JOIN </xsl:text>
   <xsl:call-template name="TargetSchemaName">
    <xsl:with-param name="ParentNode" select="."/>
   </xsl:call-template>
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa;</xsl:text>
   </xsl:if>
   <xsl:text> ON (</xsl:text>
   <xsl:call-template name="TargetSchemaName">
    <xsl:with-param name="ParentNode" select="sxml:JOIN_LIST/sxml:JOIN_LIST_ITEM[1]"/>
   </xsl:call-template>
   <xsl:text>."</xsl:text>
   <xsl:value-of select="sxml:JOIN_LIST/sxml:JOIN_LIST_ITEM[1]/sxml:COL"/>
   <xsl:text>"=</xsl:text>
   <xsl:call-template name="TargetSchemaName">
    <xsl:with-param name="ParentNode" select="sxml:JOIN_LIST/sxml:JOIN_LIST_ITEM[2]"/>
   </xsl:call-template>
   <xsl:text>."</xsl:text>
   <xsl:value-of select="sxml:JOIN_LIST/sxml:JOIN_LIST_ITEM[2]/sxml:COL"/>
   <xsl:text>")</xsl:text>
  </xsl:for-each>
 </xsl:template>
 <xsl:template match="sxml:ORDER">
  <!-- *******************************************************************
Template: ORDER
******************************************************************** -->
  <xsl:text> BY </xsl:text>
  <xsl:choose>
   <xsl:when test="sxml:INTERLEAVED and not(sxml:INTERLEAVED/@src='1')">INTERLEAVED</xsl:when>
   <xsl:otherwise>LINEAR</xsl:otherwise>
  </xsl:choose>
  <xsl:text> ORDER (</xsl:text>
  <xsl:apply-templates select="sxml:COLUMN_GROUPS"/>
  <xsl:text>)</xsl:text>
 </xsl:template>
 <xsl:template match="sxml:COLUMN_GROUPS">
  <!-- *******************************************************************
Template: COLUMN_GROUPS
******************************************************************** -->
  <xsl:variable name="ThereAreGroups" select="count(sxml:COLUMN_GROUP[not(@src='1')])!=1"/>
  <xsl:for-each select="sxml:COLUMN_GROUP[not(@src='1')]">
   <xsl:if test="$ThereAreGroups">(</xsl:if>
   <xsl:for-each select="sxml:COL_LIST/sxml:COL_LIST_ITEM[not(@src='1')]">
    <xsl:call-template name="SchemaName">
     <xsl:with-param name="ParentNode" select="."/>
    </xsl:call-template>
    <xsl:text>."</xsl:text>
    <xsl:value-of select="sxml:COL"/>
    <xsl:text>"</xsl:text>
    <xsl:choose>
     <xsl:when test="position()!=last()">
      <xsl:text>,</xsl:text>
      <xsl:if test="$PRETTY=1">
       <xsl:text>&#xa;  </xsl:text>
      </xsl:if>
     </xsl:when>
     <xsl:otherwise>
      <xsl:if test="$ThereAreGroups">)</xsl:if>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:for-each>
   <xsl:if test="position()!=last()">,</xsl:if>
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa;  </xsl:text>
   </xsl:if>
  </xsl:for-each>
 </xsl:template>
 <xsl:template name="DoZonemapSxD">
  <!-- *******************************************************************
Template: DoZonemapSxD - Zonemap conversion from SXML to DDL 
******************************************************************** -->
  <xsl:if test="$PRETTY=1">
   <xsl:text>&#xa;</xsl:text>
  </xsl:if>
  <xsl:choose>
   <xsl:when test="sxml:ZONEMAP and not(sxml:ZONEMAP/@src='1')">
    <xsl:text> WITH MATERIALIZED ZONEMAP ( "</xsl:text>
    <xsl:value-of select="sxml:ZONEMAP"/>
    <xsl:text>" )</xsl:text>
   </xsl:when>
   <xsl:otherwise>
    <xsl:text> WITHOUT MATERIALIZED ZONEMAP</xsl:text>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>
 <xsl:template name="LobProperties">
  <xsl:param name="StorageTable" select="''"/>
  <xsl:param name="ModifyLobStorage">0</xsl:param>
  <!-- *******************************************************************
Template: LobProperties
Parameters:
 StorageTable
 ModifyLobStorage - 1 = generating ALTER TABLE MODIFY LOB
******************************************************************** -->
  <xsl:if test="$ModifyLobStorage=0">
   <xsl:choose>
    <!--  If the element has the src attribute set to '1',
          we know the element is in a diff doc and came from document 1.
          We only want the value from document 2. -->
    <xsl:when test="$StorageTable/sxml:STORAGE_IN_ROW">
     <xsl:choose>
      <xsl:when test="$StorageTable/sxml:STORAGE_IN_ROW/@src='1'"> DISABLE STORAGE IN ROW</xsl:when>
      <xsl:otherwise> ENABLE STORAGE IN ROW</xsl:otherwise>
     </xsl:choose>
    </xsl:when>
    <xsl:otherwise> DISABLE STORAGE IN ROW</xsl:otherwise>
   </xsl:choose>
   <xsl:apply-templates select="$StorageTable/sxml:CHUNK"/>
  </xsl:if>
  <!-- Process RETENTION for both BASICFILE and SECUREFILE lobs. -->
  <xsl:choose>
   <xsl:when test="$StorageTable/sxml:RETENTION [not(@src='1')]">
    <xsl:apply-templates select="$StorageTable/sxml:RETENTION"/>
   </xsl:when>
   <!-- PCTVERSION is only applicable for BASICFILE lobs and should
      only be present if RETENTION was not. PCTVERSION should 
      never be present in a SECUREFILE lob!
      However, PCTVERSION and RETENTION can both occur in a diff
      doc and therefore we need to decide which is appropriate for these
      cases.
-->
   <xsl:when test="$StorageTable/sxml:PCTVERSION[not(@src='1')]">
    <xsl:apply-templates select="$StorageTable/sxml:PCTVERSION"/>
   </xsl:when>
  </xsl:choose>
  <xsl:if test="$StorageTable/sxml:CACHE
            or $StorageTable/sxml:LOGGING
            or $StorageTable/sxml:LOBENCRYPT
            or $StorageTable/sxml:LOBCOMPRESS
            or $StorageTable/sxml:DEDUPLICATE
            or $StorageTable/sxml:VALIDATE
            or $StorageTable/sxml:STORAGE">
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa; </xsl:text>
   </xsl:if>
  </xsl:if>
  <xsl:apply-templates select="$StorageTable/sxml:CACHE"/>
  <xsl:apply-templates select="$StorageTable/sxml:LOGGING"/>
  <!-- We must account for alterxml transforms as well. Therefore it not enough 
         just to check for SECUREFILE because it might indicate 'delete' within a 
         diff doc (i.e., /sxml:SECUREFILE/@src=1)
-->
  <xsl:if test="($ModifyLobStorage=0 and $StorageTable/sxml:SECUREFILE) and
            not($StorageTable/sxml:SECUREFILE/@src='1')">
   <xsl:choose>
    <xsl:when test="$StorageTable/sxml:LOBENCRYPT">
     <xsl:apply-templates select="$StorageTable/sxml:LOBENCRYPT"/>
    </xsl:when>
    <xsl:when test="$StorageTable/sxml:LOBDECRYPT"> DECRYPT</xsl:when>
   </xsl:choose>
   <xsl:choose>
    <xsl:when test="sxml:STORAGE_TABLE/sxml:LOBCOMPRESS">
     <xsl:apply-templates select="$StorageTable/sxml:LOBCOMPRESS"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text> NOCOMPRESS </xsl:text>
    </xsl:otherwise>
   </xsl:choose>
   <xsl:apply-templates select="$StorageTable/sxml:VALIDATE"/>
   <xsl:choose>
    <xsl:when test="sxml:STORAGE_TABLE/sxml:DEDUPLICATE">
     <xsl:apply-templates select="$StorageTable/sxml:DEDUPLICATE"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:text>KEEP_DUPLICATES </xsl:text>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:if>
  <xsl:apply-templates select="$StorageTable/sxml:STORAGE"/>
 </xsl:template>
 <xsl:template match="sxml:RETENTION">
  <!-- *******************************************************************
Template: RETENTION
       Process RETENTION for both SECUREFILE and BASICFILE lobs.
       If present RETENTION will never have a value for Basicfile lobs.
      However, for SECUREFILE lobs retention can be valueless or
      one of the following values:
            MAX
            MIN  integer
            AUTO
            NONE
******************************************************************** -->
  <xsl:text> RETENTION </xsl:text>
  <xsl:value-of select="."/>
  <xsl:apply-templates select="../sxml:MINTIME"/>
 </xsl:template>
 <xsl:template match="sxml:CACHE">
  <!-- *******************************************************************
Template: CACHE
******************************************************************** -->
  <xsl:choose>
   <xsl:when test=".='Y'"> CACHE</xsl:when>
   <xsl:when test=".='N'"> NOCACHE</xsl:when>
   <xsl:when test=".='READS'"> CACHE READS</xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:LOBCOMPRESS">
  <!-- *******************************************************************
Template: LOBCOMPRESS
******************************************************************** -->
  <xsl:choose>
   <xsl:when test=".='HIGH'"> COMPRESS HIGH </xsl:when>
   <xsl:when test=".='MEDIUM'"> COMPRESS MEDIUM </xsl:when>
   <xsl:when test=".='LOW'"> COMPRESS LOW </xsl:when>
   <xsl:when test=".='N'"> NOCOMPRESS </xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:DEDUPLICATE">
  <!-- *******************************************************************
Template: DEDUPLICATE
******************************************************************** -->
  <xsl:choose>
   <xsl:when test=".='OBJECT'"> DEDUPLICATE OBJECT</xsl:when>
   <xsl:when test=".='LOB'"> DEDUPLICATE LOB</xsl:when>
   <xsl:when test=".='N'"> KEEP_DUPLICATES</xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:VALIDATE">
  <!-- *******************************************************************
Template: VALIDATE
******************************************************************** -->
  <xsl:choose>
   <xsl:when test=".='Y'"> VALIDATE</xsl:when>
  </xsl:choose>
 </xsl:template>
 <xsl:template match="sxml:MINTIME">
  <!-- *******************************************************************
Template: MIN Parameter for RETENTION
******************************************************************** -->
  <xsl:if test=". != 0">
   <xsl:value-of select="."/>
  </xsl:if>
 </xsl:template>
 <xsl:template match="sxml:PERIOD_LIST">
  <xsl:param name="ParentNode" select="''"/>
  <!-- *******************************************************************
Template: PERIOD_LIST
 ParentNode - parent of SCHEMA and NAME
  Emits an ALTER TABLE statement to ADD each PERIOD_LIST_ITEM

Note: the terminator is at the beginning of the loop because it needs to
      terminate the CREATE TABLE (kustabld). The kustabld stylesheet will
      also terminate the last PERIOD_LIST_ITEM where it normally terminates
      the CREATE TABLE 
******************************************************************** -->
  <xsl:for-each select="sxml:PERIOD_LIST_ITEM">
   <xsl:if test="$SQLTERMINATOR=1">;</xsl:if>
   <xsl:if test="$PRETTY=1">
    <xsl:text>&#xa; </xsl:text>
   </xsl:if>
   <xsl:call-template name="AddPeriod">
    <xsl:with-param name="ParentNode" select="$ParentNode"/>
   </xsl:call-template>
  </xsl:for-each>
 </xsl:template>
 <xsl:template name="AddPeriod">
  <xsl:param name="ParentNode" select="''"/>
  <!-- *******************************************************************
Template: AddPeriod
 ParentNode - parent of SCHEMA and NAME
Current Node: PERIOD_LIST_ITEM
  Emits an ALTER TABLE statement to ADD a PERIOD_LIST_ITEM
  Used by both SXMLDDL and ALTERXML.
******************************************************************** -->
  <xsl:text> ALTER TABLE </xsl:text>
  <xsl:call-template name="SchemaName">
   <xsl:with-param name="ParentNode" select="$ParentNode"/>
  </xsl:call-template>
  <xsl:text> ADD ( PERIOD FOR "</xsl:text>
  <xsl:value-of select="sxml:VALID_TIME_COLUMN"/>
  <xsl:text>"</xsl:text>
  <xsl:if test="sxml:START_TIME_COLUMN">
   <xsl:text>("</xsl:text>
   <xsl:value-of select="sxml:START_TIME_COLUMN"/>
   <xsl:text>","</xsl:text>
   <xsl:value-of select="sxml:END_TIME_COLUMN"/>
   <xsl:text>")</xsl:text>
  </xsl:if>
  <xsl:text>)</xsl:text>
 </xsl:template>
 <xsl:template name="DropPeriod">
  <xsl:param name="ParentNode" select="''"/>
  <!-- *******************************************************************
Template: DropPeriod
 ParentNode - parent of SCHEMA and NAME
Current Node: PERIOD_LIST_ITEM
  Emits an ALTER TABLE statement to DROP a PERIOD_LIST_ITEM
  Used by ALTERXML.
******************************************************************** -->
  <xsl:text> ALTER TABLE </xsl:text>
  <xsl:call-template name="SchemaName">
   <xsl:with-param name="ParentNode" select="$ParentNode"/>
  </xsl:call-template>
  <xsl:text> DROP ( PERIOD FOR "</xsl:text>
  <xsl:value-of select="sxml:VALID_TIME_COLUMN"/>
  <xsl:text>" )</xsl:text>
 </xsl:template>
</xsl:stylesheet>

OHA YOOOO