home *** CD-ROM | disk | FTP | other *** search
/ ftp.tcs3.com / ftp.tcs3.com.tar / ftp.tcs3.com / DRIVERS / Audio / Office2010 / ProPlus.WW / ProPsWW.cab / AS_ClientMsjet_xsl_32.C16C67A1_5ADC_4C44_B6AE_A40000020FCC < prev    next >
Extensible Markup Language  |  2009-03-29  |  29KB  |  683 lines

  1. <?xml version="1.0"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" version="1.0" xmlns:mssqlcrt="urn:sql-microsoft-com:sqlcrt" xmlns:mssqldbg="urn:sql-microsoft-com:sqldbg">
  3.     <xsl:output method="xml" indent="yes"/>
  4.  
  5.     <!-- This ALWAYS GENERATED file contains the definitions for the cartridges
  6.                  Microsoft Cartridge Interfaces (Analysis Services 2005)
  7.                  (C) Copyright 1988 - 2003 By Microsoft Corporation.      -->
  8.  
  9.  
  10.     <!-- Area of Custom parametrizations: these may be modified by customers for specific query customizations  -->
  11.     <!-- post-select-query-hint will append the customer-defined string at the end of the generated SELECT statement - e.g. WITH UR -->
  12.     <xsl:param name="post-select-query-hint"></xsl:param>
  13.  
  14.  
  15.     <!-- Microsoft Jet (Access DB) pluggable cartridge                    -->
  16.  
  17.     <!-- Area of STANDARD parametrizations: these are externally passed   -->
  18.     <xsl:param name="in_CanUseParams">yes</xsl:param>
  19.     <xsl:param name="in_IdentStartQuotingCharacter">[</xsl:param>
  20.     <xsl:param name="in_IdentEndQuotingCharacter">]</xsl:param>
  21.     <xsl:param name="in_StringStartQuotingCharacter">'</xsl:param>
  22.     <xsl:param name="in_StringEndQuotingCharacter">'</xsl:param>
  23.     <xsl:param name="in_IdentInvalidCharacters">[].!</xsl:param>
  24.     
  25.     <!-- Area of CORE parametrizations: These are externally checked      -->
  26.     <mssqlcrt:provider type="prefix" managed="yes" native="yes">MS Jet</mssqlcrt:provider>
  27.   <mssqlcrt:provider type="prefix" managed="yes" native="yes">ACCESS</mssqlcrt:provider>
  28.   <mssqlcrt:parameter-style native="unnamed" managed="named"/>
  29.  
  30.     <!-- todo: add time support -->
  31.     <mssqlcrt:capabilities>
  32.         <mssqlcrt:supports-update/>
  33.         <mssqlcrt:supports-insert/>
  34.         <mssqlcrt:supports-subselect/>
  35.         <mssqlcrt:supports-table-alias/>
  36.         <mssqlcrt:supports-column-alias/>
  37.         <mssqlcrt:supports-union/>
  38.         <mssqlcrt:supports-union-all/>
  39.         
  40.         <mssqlcrt:limit-max-connections-count>4</mssqlcrt:limit-max-connections-count>
  41.         
  42.         <mssqlcrt:remote-connection-string-translation-behavior>1</mssqlcrt:remote-connection-string-translation-behavior>
  43.  
  44.         <!-- Map from MSDAInitialize connection string to SQLOLEDB connection string -->
  45.         <mssqlcrt:remote-connection-string-mappings>
  46.             <mssqlcrt:remote-connection-string-mapping>
  47.                 <mssqlcrt:datasource-property>Provider</mssqlcrt:datasource-property>
  48.                 <mssqlcrt:remote-property></mssqlcrt:remote-property>
  49.             </mssqlcrt:remote-connection-string-mapping>
  50.             <mssqlcrt:remote-connection-string-mapping>
  51.                 <mssqlcrt:datasource-property>Data Source</mssqlcrt:datasource-property>
  52.                 <mssqlcrt:remote-property>Database</mssqlcrt:remote-property>
  53.             </mssqlcrt:remote-connection-string-mapping>
  54.             <mssqlcrt:remote-connection-string-mapping>
  55.                 <mssqlcrt:datasource-property>Initial Catalog</mssqlcrt:datasource-property>
  56.                 <mssqlcrt:remote-property></mssqlcrt:remote-property>
  57.             </mssqlcrt:remote-connection-string-mapping>
  58.             <mssqlcrt:remote-connection-string-mapping>
  59.                 <mssqlcrt:datasource-property>User ID</mssqlcrt:datasource-property>
  60.                 <mssqlcrt:remote-property>UID</mssqlcrt:remote-property>
  61.             </mssqlcrt:remote-connection-string-mapping>
  62.             <mssqlcrt:remote-connection-string-mapping>
  63.                 <mssqlcrt:datasource-property>Password</mssqlcrt:datasource-property>
  64.                 <mssqlcrt:remote-property>PWD</mssqlcrt:remote-property>
  65.             </mssqlcrt:remote-connection-string-mapping>
  66.             <mssqlcrt:remote-connection-string-mapping>
  67.                 <mssqlcrt:datasource-property>Persist Security Info</mssqlcrt:datasource-property>
  68.                 <mssqlcrt:remote-property></mssqlcrt:remote-property>
  69.             </mssqlcrt:remote-connection-string-mapping>
  70.         </mssqlcrt:remote-connection-string-mappings>
  71.     </mssqlcrt:capabilities>
  72.  
  73.     <mssqlcrt:schema-classes>
  74.         <mssqlcrt:schema-class>
  75.             <mssqlcrt:managed-provider>System.Data.OleDb</mssqlcrt:managed-provider>
  76.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OleDbSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  77.             <mssqlcrt:query-designer>
  78.                 <mssqlcrt:type>Microsoft.DataWarehouse.Controls.OleDbQueryDesigner, Microsoft.DataWarehouse</mssqlcrt:type>
  79.             </mssqlcrt:query-designer>
  80.         </mssqlcrt:schema-class>
  81.         <mssqlcrt:schema-class>
  82.             <mssqlcrt:managed-provider>System.Data.Odbc</mssqlcrt:managed-provider>
  83.             <mssqlcrt:type>Microsoft.DataWarehouse.Design.OdbcSchema, Microsoft.DataWarehouse</mssqlcrt:type>
  84.         </mssqlcrt:schema-class>
  85.     </mssqlcrt:schema-classes>
  86.  
  87.     <!-- Area of internal parametrizations                                -->
  88.     <!-- overrideOfUseParams:
  89.              yes      = use always parametric queries
  90.              no       = never use parametric queries
  91.              nosubsel = use as yes, but not on subselects
  92.              auto     = use the value of in_CanUseParams to determine     -->
  93.     <xsl:variable name="overrideOfUseParams">auto</xsl:variable>
  94.     <!-- shouldProduceDebug:
  95.              yes      = produce debug information
  96.              no       = do not produce debug information                  -->
  97.     <xsl:variable name="shouldProduceDebug">yes</xsl:variable>
  98.  
  99.     <!-- Area of global variables initializations                         -->
  100.     <xsl:variable name="UseParams">
  101.         <xsl:choose>
  102.             <xsl:when test="normalize-space($overrideOfUseParams) = 'yes' or (normalize-space($overrideOfUseParams) = 'auto' and normalize-space($in_CanUseParams)='yes')">yes</xsl:when>
  103.             <xsl:when test="normalize-space($overrideOfUseParams) = 'nosubsel'">nosubsel</xsl:when>
  104.             <xsl:otherwise>no</xsl:otherwise>
  105.         </xsl:choose>
  106.     </xsl:variable>
  107.     <xsl:variable name="ProduceDebug" select="$shouldProduceDebug"/>
  108.     <xsl:variable name="IdentifierStartQuotingCharacter" select="normalize-space($in_IdentStartQuotingCharacter)"/>
  109.     <xsl:variable name="IdentifierEndQuotingCharacter" select="normalize-space($in_IdentEndQuotingCharacter)"/>
  110.     <xsl:variable name="StringStartQuotingCharacter" select="normalize-space($in_StringStartQuotingCharacter)"/>
  111.     <xsl:variable name="StringEndQuotingCharacter" select="normalize-space($in_StringEndQuotingCharacter)"/>
  112.  
  113.     <!-- Generated statement packaging                                    -->
  114.     <xsl:template match="/">
  115.         <xsl:element name="Statement">
  116.  
  117.             <!-- Generate query                                           -->
  118.             <xsl:element name="Text">
  119.                 <xsl:apply-templates select="./Statement/*[1]"/>
  120.             </xsl:element>
  121.  
  122.             <!-- Generate parameters                                      -->
  123.             <xsl:if test="count(./Statement/Parameters/Parameter)!=0 and ((normalize-space($UseParams)='yes') or (normalize-space($UseParams)='nosubsel'))">
  124.                 <xsl:element name="Parameters">
  125.                     <xsl:choose>
  126.                         <xsl:when test="/Statement/*[1]//Parameter/@ParamName">
  127.                             <xsl:for-each select="./Statement/Parameters/Parameter">
  128.                                 <xsl:element name="Parameter">
  129.                                     <xsl:attribute name="ref">
  130.                                         <xsl:value-of select="./@id"/>
  131.                                     </xsl:attribute>
  132.                                 </xsl:element>
  133.                             </xsl:for-each>
  134.                         </xsl:when>
  135.                         <xsl:otherwise>
  136.                             <xsl:for-each select="./Statement/*[1]//Parameter">
  137.                                 <xsl:element name="Parameter">
  138.                                     <xsl:attribute name="ref">
  139.                                         <xsl:value-of select="./@ref"/>
  140.                                     </xsl:attribute>
  141.                                 </xsl:element>
  142.                             </xsl:for-each>
  143.                         </xsl:otherwise>
  144.                     </xsl:choose>
  145.                 </xsl:element>
  146.             </xsl:if>
  147.  
  148.             <!-- Generate debug info                                      -->
  149.             <xsl:if test="$ProduceDebug='yes'">
  150.                 <xsl:element name="mssqldbg:DebugInfo">
  151.                     <xsl:element name="mssqldbg:GenerateParametricInfo">
  152.                         <xsl:attribute name="mssqldbg:Value">
  153.                             <xsl:value-of select="$UseParams"/>
  154.                         </xsl:attribute>
  155.                         <xsl:element name="mssqldbg:External">
  156.                             <xsl:value-of select="$in_CanUseParams"/>
  157.                         </xsl:element>
  158.                         <xsl:element name="mssqldbg:Internal">
  159.                             <xsl:value-of select="$overrideOfUseParams"/>
  160.                         </xsl:element>
  161.                     </xsl:element>
  162.                 </xsl:element>
  163.             </xsl:if>
  164.  
  165.         </xsl:element>
  166.     </xsl:template>
  167.  
  168.     <!-- Union statement                                                  -->
  169.     <xsl:template match="Union">
  170.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  171.             (
  172.         </xsl:if>
  173.             <xsl:call-template name="print-children-list">
  174.                 <xsl:with-param name="operator" select="' UNION '"/>
  175.             </xsl:call-template>
  176.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  177.             )
  178.         </xsl:if>
  179.     </xsl:template>
  180.  
  181.     <!-- Union All statement                                                  -->
  182.     <xsl:template match="UnionAll">
  183.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  184.             (
  185.         </xsl:if>
  186.             <xsl:call-template name="print-children-list">
  187.                 <xsl:with-param name="operator" select="' UNION ALL '"/>
  188.             </xsl:call-template>
  189.         <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert'">
  190.             )
  191.         </xsl:if>
  192.     </xsl:template>
  193.  
  194.     <!-- Select statement                                                 -->
  195.     <xsl:template match="Select">
  196.         <xsl:choose>
  197.             <xsl:when test="name(./*[1])='ColumnExpressions' and name(./*[1]/*[1])='Count' and name(./*[1]/*[1]/*[1])='Distinct'">
  198.                 SELECT COUNT(*) FROM 
  199.                 ( SELECT <xsl:apply-templates select="./ColumnExpressions/Count/Distinct"/> <xsl:apply-templates select="./*[1]/*[1]/*[2]"/>
  200.                 <xsl:apply-templates select="./Sources"/>
  201.                 <xsl:apply-templates select="./Where"/>
  202.                 <xsl:apply-templates select="./GroupBy"/> )
  203.                 AS [TableAlias]
  204.             </xsl:when>
  205.             <xsl:otherwise>
  206.                 <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  207.                     (
  208.                 </xsl:if>
  209.                 SELECT <xsl:apply-templates select="./Distinct"/>
  210.                     <xsl:apply-templates select="./ColumnExpressions"/>
  211.                     <xsl:apply-templates select="./Sources"/>
  212.                     <xsl:apply-templates select="./Where"/>
  213.                     <xsl:apply-templates select="./GroupBy"/>
  214.                     <xsl:apply-templates select="./OrderBy"/>
  215.                 
  216.                     <xsl:if test="name(..) = 'Statement'">
  217.                         <xsl:text> </xsl:text><xsl:value-of select="$post-select-query-hint"/>
  218.                     </xsl:if>
  219.                 <xsl:if test="name(..) != 'Statement' and name(..) != 'Insert' and name(..) != 'Union' and name(..) != 'UnionAll'">
  220.                     )
  221.                 </xsl:if>
  222.             </xsl:otherwise>
  223.         </xsl:choose>
  224.     </xsl:template>
  225.  
  226.     <!-- Update statement                                                 -->
  227.     <xsl:template match="Update">
  228.         UPDATE <xsl:apply-templates select="./Target"/>
  229.             <xsl:apply-templates select="./Where"/>
  230.     </xsl:template>
  231.  
  232.     <!-- Insert statement                                                 -->
  233.     <xsl:template match="Insert">
  234.         INSERT INTO <xsl:apply-templates select="./Target"/>
  235.         <xsl:apply-templates select="./Select"/>
  236.     </xsl:template>
  237.  
  238.     <!-- Delete statement                                                 -->
  239.     <xsl:template match="Delete">
  240.         DELETE FROM <xsl:apply-templates select="./Target"/>
  241.             <xsl:apply-templates select="./Where"/>
  242.     </xsl:template>
  243.  
  244.     <!-- Drop statement                                                   -->
  245.     <xsl:template match="Drop">
  246.         DROP <xsl:apply-templates select="./*"/>
  247.     </xsl:template>
  248.  
  249.     <!-- Create statement                                                 -->
  250.     <xsl:template match="Create">
  251.         CREATE <xsl:apply-templates select="./*[1]"/>
  252.         <xsl:choose>
  253.             <xsl:when test="name(./*[1]) = 'Table'">( <xsl:apply-templates select="./*[2]"/> )</xsl:when>
  254.         </xsl:choose>
  255.     </xsl:template>
  256.  
  257.     <xsl:template match="Distinct">
  258.         DISTINCT
  259.     </xsl:template>
  260.  
  261.     <xsl:template match="As">
  262.         <xsl:apply-templates select="./*[1]"/> AS <xsl:apply-templates select="./*[2]"/>
  263.     </xsl:template>
  264.  
  265.     <xsl:template match="Sources">
  266.         FROM <xsl:call-template name="print-children-list"/>
  267.     </xsl:template>
  268.  
  269.     <xsl:template match="ColumnDefinitions">
  270.         <xsl:call-template name="print-children-list"/>
  271.     </xsl:template>
  272.  
  273.     <xsl:template match="GroupBy">
  274.         GROUP BY <xsl:call-template name="print-children-list"/>
  275.     </xsl:template>
  276.  
  277.     <xsl:template match="OrderBy">
  278.         ORDER BY <xsl:call-template name="print-children-list"/>
  279.     </xsl:template>
  280.  
  281.     <xsl:template match="Where">
  282.         WHERE <xsl:apply-templates select="./*"/>
  283.     </xsl:template>
  284.  
  285.     <xsl:template match="Having">
  286.         HAVING <xsl:apply-templates select="./*"/>
  287.     </xsl:template>
  288.  
  289.     <xsl:template match="ColumnExpressions">
  290.         <xsl:call-template name="print-children-list"/>
  291.     </xsl:template>
  292.  
  293.     <xsl:template match="ColumnUpdates">
  294.         <xsl:call-template name="print-children-list"/>
  295.     </xsl:template>
  296.  
  297.     <xsl:template match="Assign">
  298.         <xsl:apply-templates select="./*[1]"/>=<xsl:apply-templates select="./*[2]"/>
  299.     </xsl:template>
  300.  
  301.     <xsl:template match="Insert/Target">
  302.         <xsl:apply-templates select="./Table"/>
  303.         (
  304.             <xsl:call-template name="print-list">
  305.                 <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[1]"/>
  306.             </xsl:call-template>
  307.         )
  308.         <xsl:if test="./*[2]/Assign">
  309.             VALUES
  310.             (
  311.                 <xsl:call-template name="print-list">
  312.                     <xsl:with-param name="value-node" select="./ColumnUpdates/*/*[2]"/>
  313.                 </xsl:call-template>
  314.             )
  315.         </xsl:if>
  316.     </xsl:template>
  317.  
  318.     <xsl:template match="Update/Target">
  319.         <xsl:apply-templates select="./Table"/>
  320.         SET <xsl:apply-templates select="./ColumnUpdates"/>
  321.     </xsl:template>
  322.  
  323.     <xsl:template match="Delete/Target">
  324.         <xsl:apply-templates select="./Table"/>
  325.     </xsl:template>
  326.  
  327.     <xsl:template match="Insert/Target/ColumnUpdates/Assign/SQLColumn[1]">
  328.         <!-- The table name is not printed for LHS of assignments in insert -->
  329.         <xsl:apply-templates select="./Column"/>
  330.     </xsl:template>
  331.  
  332.     <xsl:template match="Create/ColumnDefinitions/SQLColumn">
  333.         <xsl:apply-templates select="./Column"/>
  334.         <xsl:apply-templates select="./Type"/>
  335.         <xsl:apply-templates select="./Usage"/>
  336.     </xsl:template>
  337.  
  338.     <xsl:template match="SQLColumn">
  339.         <xsl:variable name="table">
  340.             <xsl:if test="name(..)!='Count' or name(./Column/*[1]) != 'Asterisk'"><xsl:apply-templates select="./Table"/></xsl:if>
  341.         </xsl:variable>
  342.         <xsl:variable name="column">
  343.             <xsl:apply-templates select="./Column"/>
  344.         </xsl:variable>
  345.         <xsl:choose>
  346.             <xsl:when test="$table = ''">
  347.                 <xsl:value-of select="$column"/>
  348.             </xsl:when>
  349.             <xsl:otherwise>
  350.                 <xsl:value-of select="concat($table,'.', $column)"/>
  351.             </xsl:otherwise>
  352.         </xsl:choose>
  353.     </xsl:template>
  354.  
  355.     <xsl:template match="Create/Database|Drop/Database">
  356.         DATABASE <xsl:apply-templates select="./Name"/>
  357.     </xsl:template>
  358.  
  359.     <xsl:template match="Table">
  360.         <xsl:call-template name="build-quoted-schema-object"/>
  361.     </xsl:template>
  362.  
  363.     <xsl:template match="Create/Table|Drop/Table">
  364.         TABLE <xsl:call-template name="build-quoted-schema-object"/>
  365.     </xsl:template>
  366.  
  367.     <xsl:template match="View">
  368.         <xsl:call-template name="build-quoted-schema-object"/>
  369.     </xsl:template>
  370.  
  371.     <xsl:template match="Drop/View">
  372.         VIEW <xsl:call-template name="build-quoted-schema-object"/>
  373.     </xsl:template>
  374.  
  375.     <xsl:template match="Index">
  376.         <xsl:apply-templates select="./Name"/>
  377.     </xsl:template>
  378.  
  379.     <xsl:template match="Drop/Index">
  380.         INDEX <xsl:apply-templates select="./Name"/>
  381.     </xsl:template>
  382.  
  383.     <xsl:template match="Column">
  384.         <xsl:apply-templates select="./Asterisk"/>
  385.         <xsl:apply-templates select="./Name"/>
  386.     </xsl:template>
  387.  
  388.     <xsl:template match="Table/Name|View/Name|Index/Name|Column/Name|Database/Name|Schema">
  389.         <xsl:call-template name="quote-identifier"/>
  390.     </xsl:template>
  391.  
  392.     <xsl:template match="Usage">
  393.         <xsl:variable name="usage"><xsl:value-of select="."/></xsl:variable>
  394.         <xsl:choose>
  395.             <xsl:when test="$usage = 'Key'">    primary key   </xsl:when>
  396.         </xsl:choose>
  397.     </xsl:template>
  398.  
  399.     <xsl:template match="OpaqueExpression">
  400.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  401.             (
  402.         </xsl:if>
  403.         <xsl:value-of select="."/>
  404.         <xsl:if test="name(..) = 'As' and name(../..) = 'Sources'">
  405.             )
  406.         </xsl:if>
  407.     </xsl:template>
  408.  
  409.     <xsl:template match="OrderExpression">
  410.         <xsl:apply-templates select="./*[1]"/>
  411.         <xsl:apply-templates select="./Asc"/>
  412.         <xsl:apply-templates select="./Desc"/>
  413.     </xsl:template>
  414.  
  415.     <xsl:template match="Asc">
  416.         ASC
  417.     </xsl:template>
  418.  
  419.     <xsl:template match="Desc">
  420.         DESC
  421.     </xsl:template>
  422.  
  423.     <!-- Print values: ? for parametric queries and convert expressions
  424.          for non-parametric queries                                       -->
  425.     <xsl:template match="Parameter">
  426.         <xsl:choose>
  427.             <xsl:when test="$UseParams = 'yes' or $UseParams = 'nosubsel'">
  428.                 <xsl:choose>
  429.                     <xsl:when test="./@ParamName">
  430.                         @<xsl:value-of select="./@ParamName"/>
  431.                     </xsl:when>
  432.                     <xsl:otherwise>
  433.                         ?
  434.                     </xsl:otherwise>
  435.                 </xsl:choose>
  436.             </xsl:when>
  437.             <xsl:otherwise>
  438.                 <xsl:call-template name="print-non-parametric-parameter-ref">
  439.                     <xsl:with-param name="parameter-reference" select="."/>
  440.                 </xsl:call-template>
  441.             </xsl:otherwise>
  442.         </xsl:choose>
  443.     </xsl:template>
  444.  
  445.     <!-- Asterisk                                                         -->
  446.     <xsl:template match="Asterisk">*</xsl:template>
  447.  
  448.     <!-- Count/Min/Max/Sum                                                -->
  449.     <xsl:template match="Count|Min|Max|Sum">
  450.         <xsl:variable name="function">
  451.             <xsl:choose>
  452.                 <xsl:when test="name()='Count'"> COUNT </xsl:when>
  453.                 <xsl:when test="name()='Min'"> MIN </xsl:when>
  454.                 <xsl:when test="name()='Max'"> MAX </xsl:when>
  455.                 <xsl:when test="name()='Sum'"> SUM </xsl:when>
  456.             </xsl:choose>
  457.         </xsl:variable>
  458.         <xsl:value-of select="$function"/>( <xsl:apply-templates select="./*[1]"/> )
  459.     </xsl:template>
  460.  
  461.     <!-- Binary expressions                                               -->
  462.     <!-- Equal/NotEqual/Greater/GreaterOrEqual/Less/LessOrEqual/In/And/Or/Plus/Minus/Divide/Multiply
  463.          expressions                                                      -->
  464.     <xsl:template match="Equal|NotEqual|Greater|GreaterOrEqual|Less|LessOrEqual|In|And|Or|Plus|Minus|Divide|Multiply">
  465.         <xsl:variable name="operator">
  466.             <xsl:choose>
  467.                 <xsl:when test="name()='Equal'">            =        </xsl:when>
  468.                 <xsl:when test="name()='NotEqual'">            <>    </xsl:when>
  469.                 <xsl:when test="name()='Greater'">            >        </xsl:when>
  470.                 <xsl:when test="name()='GreaterOrEqual'">    >=        </xsl:when>
  471.                 <xsl:when test="name()='Less'">                <    </xsl:when>
  472.                 <xsl:when test="name()='LessOrEqual'">        <=    </xsl:when>
  473.                 <xsl:when test="name()='In'">                IN        </xsl:when>
  474.                 <xsl:when test="name()='And'">                AND        </xsl:when>
  475.                 <xsl:when test="name()='Or'">                OR        </xsl:when>
  476.                 <xsl:when test="name()='Plus'">                +        </xsl:when>
  477.                 <xsl:when test="name()='Minus'">            -        </xsl:when>
  478.                 <xsl:when test="name()='Divide'">            /        </xsl:when>
  479.                 <xsl:when test="name()='Multiply'">            *        </xsl:when>
  480.             </xsl:choose>
  481.         </xsl:variable>
  482.         (
  483.             <xsl:call-template name="print-children-list">
  484.                 <xsl:with-param name="operator" select="$operator"/>
  485.             </xsl:call-template>
  486.         )
  487.     </xsl:template>
  488.  
  489.     <!-- Postfix unary expressions                                        -->
  490.     <!-- IsNull
  491.          expressions                                                      -->
  492.     <xsl:template match="IsNull">
  493.         <xsl:variable name="operator">
  494.             <xsl:choose>
  495.                 <xsl:when test="name()='IsNull'">            IS NULL        </xsl:when>
  496.             </xsl:choose>
  497.         </xsl:variable>
  498.         (
  499.             <xsl:apply-templates select="./*[1]"/>
  500.             <xsl:value-of select="$operator"/>
  501.         )
  502.     </xsl:template>
  503.  
  504.     <!-- Types                                                            -->
  505.     <xsl:template match="Type">
  506.         <xsl:variable name="type-val"><xsl:value-of select="normalize-space(./text())"/></xsl:variable>
  507.         <xsl:choose>
  508.             <xsl:when test="$type-val = 'DBTYPE_BSTR'">    varchar      </xsl:when>
  509.             <xsl:when test="$type-val = 'DBTYPE_WSTR'">    varchar      </xsl:when>
  510.             <xsl:when test="$type-val = 'DBTYPE_STR'">     varchar      </xsl:when>
  511.             <xsl:when test="$type-val = 'DBTYPE_BOOL'">    bit          </xsl:when>
  512.             <xsl:when test="$type-val = 'DBTYPE_I1'">      tinyint      </xsl:when>
  513.             <xsl:when test="$type-val = 'DBTYPE_I2'">      smallint     </xsl:when>
  514.             <xsl:when test="$type-val = 'DBTYPE_I4'">      int          </xsl:when>
  515.             <xsl:when test="$type-val = 'DBTYPE_I8'">      long         </xsl:when>
  516.             <xsl:when test="$type-val = 'DBTYPE_UI1'">     tinyint      </xsl:when>
  517.             <xsl:when test="$type-val = 'DBTYPE_UI2'">     smallint     </xsl:when>
  518.             <xsl:when test="$type-val = 'DBTYPE_UI4'">     int          </xsl:when>
  519.             <xsl:when test="$type-val = 'DBTYPE_UI8'">     long         </xsl:when>
  520.             <xsl:when test="$type-val = 'DBTYPE_R4'">      float        </xsl:when>
  521.             <xsl:when test="$type-val = 'DBTYPE_R8'">      real         </xsl:when>
  522.             <xsl:when test="$type-val = 'DBTYPE_DATE'">    datetime     </xsl:when>
  523.             <xsl:when test="$type-val = 'DBTYPE_DBTIMESTAMP'">    datetime     </xsl:when>
  524.             <xsl:when test="$type-val = 'DBTYPE_CY'">      money        </xsl:when>
  525.             <xsl:when test="$type-val = 'DBTYPE_VARIANT'"> sql_variant  </xsl:when>
  526.             <xsl:when test="$type-val = 'DBTYPE_GUID'"> guid </xsl:when>
  527.             <xsl:when test="$type-val = 'DBTYPE_ByteArray'"> varbinary  </xsl:when>
  528.             <xsl:when test="$type-val = 'DBTYPE_DECIMAL'"> decimal      </xsl:when>
  529.         </xsl:choose>
  530.         <xsl:apply-templates select="./Size"/>
  531.         <xsl:apply-templates select="./Precision"/>
  532.         <xsl:apply-templates select="./Scale"/>
  533.     </xsl:template>
  534.  
  535.     <!-- Size (optional)                                                  -->
  536.     <xsl:template match="Size">
  537.     ( <xsl:value-of select="./text()"/> )
  538.     </xsl:template>
  539.     
  540.     <!-- Precision (optional)                                                  -->
  541.     <xsl:template match="Precision">
  542.     ( <xsl:value-of select="./text()"/>
  543.     </xsl:template>
  544.  
  545.     <!-- Scale (optional)                                                  -->
  546.     <xsl:template match="Scale">
  547.     , <xsl:value-of select="./text()"/> )
  548.     </xsl:template>    
  549.     <!-- By default don't do anything                                     -->
  550.     <xsl:template match="*">
  551.     </xsl:template>
  552.  
  553.     <!-- Print a schema object                                               -->
  554.     <xsl:template name="build-quoted-schema-object"> 
  555.         <xsl:param name="schema-object-node" select="."/>
  556.  
  557.         <xsl:variable name="schema">
  558.             <xsl:apply-templates select="$schema-object-node/Schema"/>
  559.         </xsl:variable>
  560.         <xsl:variable name="table">
  561.             <xsl:apply-templates select="$schema-object-node/Name"/>
  562.         </xsl:variable>
  563.         <xsl:choose>
  564.             <xsl:when test="$schema = ''">
  565.                 <xsl:value-of select="$table"/>
  566.             </xsl:when>
  567.             <xsl:otherwise>
  568.                 <xsl:value-of select="concat($schema,'.', $table)"/>
  569.             </xsl:otherwise>
  570.         </xsl:choose>
  571.     </xsl:template>
  572.  
  573.     <!-- Convert an identifier to the OLEDB quotation form                -->
  574.     <xsl:template name="quote-identifier"> 
  575.         <xsl:param name="identifier" select="."/>
  576.  
  577.         <xsl:value-of select="$IdentifierStartQuotingCharacter"/>
  578.         <xsl:call-template name="normalize-entity-aux">
  579.             <xsl:with-param name="entity" select="$identifier"/>
  580.             <xsl:with-param name="end-quoting-char" select="$IdentifierEndQuotingCharacter"/>
  581.         </xsl:call-template>
  582.         <xsl:value-of select="$IdentifierEndQuotingCharacter"/>
  583.     </xsl:template>
  584.  
  585.     <!-- Convert a string to the string quotation form                    -->
  586.     <xsl:template name="quote-string"> 
  587.         <xsl:param name="string" select="."/>
  588.  
  589.         <xsl:value-of select="$StringStartQuotingCharacter"/>
  590.         <xsl:call-template name="normalize-entity-aux">
  591.             <xsl:with-param name="entity" select="$string"/>
  592.             <xsl:with-param name="end-quoting-char" select="$StringEndQuotingCharacter"/>
  593.         </xsl:call-template>
  594.         <xsl:value-of select="$StringEndQuotingCharacter"/>
  595.     </xsl:template>
  596.  
  597.     <!-- Convert an entity to the quotation form (recursive, aux)  by
  598.          duplicating the end quoting character                            -->
  599.     <xsl:template name="normalize-entity-aux"> 
  600.         <xsl:param name="entity"/>
  601.         <xsl:param name="end-quoting-char"/>
  602.  
  603.         <xsl:choose>
  604.             <xsl:when test="contains($entity, $end-quoting-char)">
  605.                 <xsl:value-of select="substring-before($entity, $end-quoting-char)"/>
  606.                 <xsl:value-of select="$end-quoting-char"/>
  607.                 <xsl:value-of select="$end-quoting-char"/>
  608.                 <xsl:call-template name="normalize-entity-aux">
  609.                     <xsl:with-param name="entity" select="substring-after($entity, $end-quoting-char)"/>
  610.                     <xsl:with-param name="end-quoting-char" select="$end-quoting-char"/>
  611.                 </xsl:call-template>
  612.             </xsl:when>
  613.             <xsl:otherwise>
  614.                 <xsl:value-of select="$entity"/>
  615.             </xsl:otherwise>
  616.         </xsl:choose>
  617.     </xsl:template>
  618.  
  619.     <!-- Print the children list                                          -->
  620.     <xsl:template name="print-children-list">
  621.         <xsl:param name="operator" select="','"/>
  622.         
  623.         <xsl:call-template name="print-list">
  624.             <xsl:with-param name="value-node" select="./*"/>
  625.             <xsl:with-param name="operator" select="$operator"/>
  626.         </xsl:call-template>
  627.     </xsl:template>
  628.  
  629.     <!-- Print a list                                                     -->
  630.     <xsl:template name="print-list">
  631.         <xsl:param name="operator" select="','"/>
  632.         <xsl:param name="value-node" select="."/>
  633.  
  634.         <xsl:for-each select="$value-node">
  635.             <xsl:apply-templates select="."/>
  636.             <xsl:if test="position()!=last()">
  637.                 <xsl:value-of select="$operator"/>
  638.             </xsl:if>
  639.         </xsl:for-each>
  640.     </xsl:template>
  641.  
  642.     <!-- Get the value of a parameter ref for the query                   -->
  643.     <xsl:template name="print-non-parametric-parameter-ref">
  644.         <xsl:param name="parameter-reference"/>
  645.  
  646.         <xsl:variable name="reference"><xsl:value-of select="$parameter-reference/@ref"/></xsl:variable>
  647.         <xsl:call-template name="print-non-parametric-parameter">
  648.             <xsl:with-param name="parameter" select="/Statement/Parameters/Parameter[@id=$reference]"/>
  649.         </xsl:call-template>
  650.     </xsl:template>
  651.  
  652.     <!-- Get the value of a parameter ref for the query                   -->
  653.     <xsl:template name="print-non-parametric-parameter">
  654.         <xsl:param name="parameter"/>
  655.  
  656.         <xsl:variable name="db-type"><xsl:value-of select="$parameter/@DBTYPE"/></xsl:variable>
  657.         <xsl:variable name="value"><xsl:value-of select="$parameter/text()"/></xsl:variable>
  658.         <xsl:choose>
  659.             <xsl:when test="$db-type = 'DBTYPE_BSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  660.             <xsl:when test="$db-type = 'DBTYPE_WSTR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  661.             <xsl:when test="$db-type = 'DBTYPE_STR'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  662.             <xsl:when test="$db-type = 'DBTYPE_BOOL'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS bit)</xsl:when>
  663.             <xsl:when test="$db-type = 'DBTYPE_I1'"><xsl:value-of select="$value"/></xsl:when>
  664.             <xsl:when test="$db-type = 'DBTYPE_I2'"><xsl:value-of select="$value"/></xsl:when>
  665.             <xsl:when test="$db-type = 'DBTYPE_I4'"><xsl:value-of select="$value"/></xsl:when>
  666.             <xsl:when test="$db-type = 'DBTYPE_I8'"><xsl:value-of select="$value"/></xsl:when>
  667.             <xsl:when test="$db-type = 'DBTYPE_UI1'"><xsl:value-of select="$value"/></xsl:when>
  668.             <xsl:when test="$db-type = 'DBTYPE_UI2'"><xsl:value-of select="$value"/></xsl:when>
  669.             <xsl:when test="$db-type = 'DBTYPE_UI4'"><xsl:value-of select="$value"/></xsl:when>
  670.             <xsl:when test="$db-type = 'DBTYPE_UI8'"><xsl:value-of select="$value"/></xsl:when>
  671.             <xsl:when test="$db-type = 'DBTYPE_R4'"><xsl:value-of select="$value"/></xsl:when>
  672.             <xsl:when test="$db-type = 'DBTYPE_R8'"><xsl:value-of select="$value"/></xsl:when>
  673.             <xsl:when test="$db-type = 'DBTYPE_DATE'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  674.             <xsl:when test="$db-type = 'DBTYPE_DBTIMESTAMP'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS datetime)</xsl:when>
  675.             <xsl:when test="$db-type = 'DBTYPE_CY'">CAST( <xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template> AS money)</xsl:when>
  676.             <xsl:when test="$db-type = 'DBTYPE_VARIANT'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  677.             <xsl:when test="$db-type = 'DBTYPE_GUID'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  678.             <xsl:when test="$db-type = 'DBTYPE_ByteArray'"><xsl:call-template name="quote-string"><xsl:with-param name="string" select="$value"/></xsl:call-template></xsl:when>
  679.             <xsl:when test="$db-type = 'DBTYPE_DECIMAL'"><xsl:value-of select="$value"/></xsl:when>
  680.         </xsl:choose>
  681.     </xsl:template>
  682. </xsl:stylesheet>
  683.