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

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

NAME
    kuaseq.xsl
DESCRIPTION
    Convert sxml SEQUENCE diff document to ALTER_XML document

MODIFIED        MM/DD/YY
    lbarton     01/13/10 - bug 8796742: translatable error messages
    lbarton     07/10/08 - bug 5709159: SQL_LIST_ITEM subelements
    lbarton     12/29/06 - more features
    rapayne     06/09/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="kuacomm.xsl"/>
 <!-- Templates -->
 <xsl:template match="sxml:SEQUENCE">
  <!-- *******************************************************************
Template: SEQUENCE - top-level template for sequences.
******************************************************************** -->
  <xsl:element name="ALTER_XML">
   <xsl:attribute name="xmlns">http://xmlns.oracle.com/ku</xsl:attribute>
   <xsl:attribute name="version">1.0</xsl:attribute>
   <!-- Object type -->
   <xsl:element name="OBJECT_TYPE">SEQUENCE</xsl:element>
   <!-- Display schema.objname for CoMPareObjects 1 and 2  -->
   <xsl:call-template name="CmpObjects">
    <xsl:with-param name="ParentNode" select="."/>
   </xsl:call-template>
   <!-- Alter list -->
   <xsl:element name="ALTER_LIST">
    <!-- NOT_ALTERABLE cases -->
    <xsl:if test="sxml:NAME/@value1">
     <xsl:call-template name="CommonNotAlterable">
      <xsl:with-param name="XpathNode" select="./sxml:NAME"/>
      <xsl:with-param name="Reason">SEQUENCE_ATTRIBUTE</xsl:with-param>
      <xsl:with-param name="Message" select="$MSG_SEQUENCE_ATTRIBUTE"/>
      <xsl:with-param name="Subst">NAME</xsl:with-param>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="sxml:START_WITH/@value1">
     <xsl:call-template name="CommonNotAlterable">
      <xsl:with-param name="XpathNode" select="./sxml:START_WITH"/>
      <xsl:with-param name="Reason">SEQUENCE_ATTRIBUTE</xsl:with-param>
      <xsl:with-param name="Message" select="$MSG_SEQUENCE_ATTRIBUTE"/>
      <xsl:with-param name="Subst">START_WITH</xsl:with-param>
     </xsl:call-template>
    </xsl:if>
    <xsl:if test="sxml:INCREMENT/@value1 or 
                  sxml:MINVALUE/@value1 or 
                  sxml:MAXVALUE/@value1 or 
                  sxml:CYCLE/@src or 
                  sxml:CACHE/@value1 or 
                  sxml:ORDER/@src">
     <xsl:element name="ALTER_LIST_ITEM">
      <xsl:call-template name="AlterSeq">
       <xsl:with-param name="Action">PARSE</xsl:with-param>
      </xsl:call-template>
      <xsl:call-template name="AlterSeq">
       <xsl:with-param name="Action">SQL</xsl:with-param>
      </xsl:call-template>
     </xsl:element>
    </xsl:if>
   </xsl:element>
  </xsl:element>
 </xsl:template>
 <xsl:template name="AlterSeq">
  <xsl:param name="Action" select="''"/>
  <!-- *******************************************************************
Template: AlterSeq
Parameters:
 Action   - PARSE or SQL
******************************************************************** -->
  <xsl:choose>
   <xsl:when test="$Action='PARSE' and ($PRS_NAME=1 or 
                                        $PRS_XPATH=1)">
    <xsl:element name="PARSE_LIST">
     <xsl:call-template name="AddXPathParseItem">
      <xsl:with-param name="Node" select="."/>
     </xsl:call-template>
     <xsl:call-template name="AddParseItem">
      <xsl:with-param name="ParseIt" select="$PRS_NAME"/>
      <xsl:with-param name="Item">NAME</xsl:with-param>
      <xsl:with-param name="Value1">
       <xsl:choose>
        <xsl:when test="sxml:NAME[@value1]">
         <xsl:value-of select="sxml:NAME/@value1"/>
        </xsl:when>
        <xsl:otherwise>
         <xsl:value-of select="sxml:NAME"/>
        </xsl:otherwise>
       </xsl:choose>
      </xsl:with-param>
     </xsl:call-template>
    </xsl:element>
   </xsl:when>
   <xsl:when test="$Action='SQL'">
    <xsl:element name="SQL_LIST">
     <xsl:element name="SQL_LIST_ITEM">
      <xsl:element name="TEXT">
       <xsl:text>ALTER SEQUENCE </xsl:text>
       <xsl:call-template name="SchemaName">
        <xsl:with-param name="ParentNode" select="."/>
       </xsl:call-template>
       <xsl:if test="sxml:INCREMENT[@value1]">
        <xsl:text> INCREMENT BY </xsl:text>
        <xsl:value-of select="sxml:INCREMENT"/>
       </xsl:if>
       <xsl:if test="sxml:MINVALUE[@value1]">
        <xsl:text> MINVALUE </xsl:text>
        <xsl:value-of select="sxml:MINVALUE"/>
       </xsl:if>
       <xsl:if test="sxml:MAXVALUE[@value1]">
        <xsl:choose>
         <xsl:when test="sxml:MAXVALUE='999999999999999999999999999'">
          <xsl:text> NOMAXVALUE </xsl:text>
         </xsl:when>
         <xsl:otherwise>
          <xsl:text> MAXVALUE </xsl:text>
          <xsl:value-of select="sxml:MAXVALUE"/>
         </xsl:otherwise>
        </xsl:choose>
       </xsl:if>
       <xsl:if test="sxml:CYCLE/@src='1'"> NOCYCLE</xsl:if>
       <xsl:if test="sxml:CYCLE/@src='2'"> CYCLE</xsl:if>
       <xsl:if test="sxml:CACHE[@value1]">
        <xsl:choose>
         <xsl:when test="sxml:CACHE='0'">
          <xsl:text> NOCACHE</xsl:text>
         </xsl:when>
         <xsl:otherwise>
          <xsl:text> CACHE </xsl:text>
          <xsl:value-of select="sxml:CACHE"/>
         </xsl:otherwise>
        </xsl:choose>
       </xsl:if>
       <xsl:if test="sxml:ORDER/@src='1'"> NOORDER</xsl:if>
       <xsl:if test="sxml:ORDER/@src='2'"> ORDER</xsl:if>
      </xsl:element>
     </xsl:element>
    </xsl:element>
   </xsl:when>
  </xsl:choose>
 </xsl:template>
</xsl:stylesheet>
