pi_framework_table.xsl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?xml version='1.0'?>
  2. <!--
  3. * Copyright (C) 2012 VoIP Embedded, Inc.
  4. *
  5. * This file is part of Kamailio, a free SIP server.
  6. *
  7. * Kamailio is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version
  11. *
  12. * Kamailio is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. -->
  21. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  22. version='1.0'
  23. xmlns:xi="http://www.w3.org/2001/XInclude">
  24. <xsl:import href="sql.xsl"/>
  25. <!-- Create the file for the table in pi_http subdirectory -->
  26. <xsl:template match="/">
  27. <xsl:variable name="path" select="concat($dir, concat('/', concat($prefix, 'table')))"/>
  28. <xsl:document href="{$path}" method="text" indent="no" omit-xml-declaration="yes">
  29. <xsl:apply-templates select="/database[1]"/>
  30. </xsl:document>
  31. </xsl:template>
  32. <xsl:template match="table">
  33. <xsl:variable name="table.name">
  34. <xsl:call-template name="get-name"/>
  35. </xsl:variable>
  36. <xsl:text>&#x9;&lt;!-- Declaration of </xsl:text>
  37. <xsl:value-of select="$table.name"/>
  38. <xsl:text> table--&gt;&#xa;</xsl:text>
  39. <xsl:text>&#x9;&lt;db_table id="</xsl:text>
  40. <xsl:value-of select="$table.name"/>
  41. <xsl:text>"&gt;&#xa;</xsl:text>
  42. <xsl:text>&#x9;&#x9;&lt;table_name&gt;</xsl:text>
  43. <xsl:value-of select="$table.name"/>
  44. <xsl:text>&lt;/table_name&gt;&#xa;</xsl:text>
  45. <xsl:text>&#x9;&#x9;&lt;db_url_id&gt;mysql&lt;/db_url_id&gt;&#xa;</xsl:text>
  46. <xsl:apply-templates select="column"/>
  47. <xsl:text>&#x9;&lt;/db_table&gt;&#xa;</xsl:text>
  48. </xsl:template>
  49. <xsl:template match="column">
  50. <xsl:text>&#x9;&#x9;&lt;column&gt;&lt;field&gt;</xsl:text>
  51. <xsl:call-template name="get-name"/>
  52. <xsl:text>&lt;/field&gt;&lt;type&gt;</xsl:text>
  53. <xsl:call-template name="column.type"/>
  54. <xsl:text>&lt;/type&gt;&lt;/column&gt;&#xa;</xsl:text>
  55. </xsl:template>
  56. <xsl:template name="column.type">
  57. <xsl:variable name="type">
  58. <xsl:call-template name="get-type"/>
  59. </xsl:variable>
  60. <xsl:choose>
  61. <xsl:when test="type[@db='mysql']">
  62. <xsl:value-of select="normalize-space(type[@db='mysql'])"/>
  63. </xsl:when>
  64. <xsl:when test="$type='char'">
  65. <xsl:text>DB1_INT</xsl:text>
  66. </xsl:when>
  67. <xsl:when test="$type='short'">
  68. <xsl:text>DB1_INT</xsl:text>
  69. </xsl:when>
  70. <xsl:when test="$type='int'">
  71. <xsl:text>DB1_INT</xsl:text>
  72. </xsl:when>
  73. <xsl:when test="$type='long'">
  74. <xsl:text>DB1_BIGINT</xsl:text>
  75. </xsl:when>
  76. <xsl:when test="$type='datetime'">
  77. <xsl:text>DB1_DATETIME</xsl:text>
  78. </xsl:when>
  79. <xsl:when test="$type='double'">
  80. <xsl:text>DB1_DOUBLE</xsl:text>
  81. </xsl:when>
  82. <xsl:when test="$type='float'">
  83. <xsl:text>DB1_DOUBLE</xsl:text>
  84. </xsl:when>
  85. <xsl:when test="$type='string'">
  86. <xsl:text>DB1_STR</xsl:text>
  87. </xsl:when>
  88. <xsl:when test="$type='binary'">
  89. <xsl:text>DB1_BLOB</xsl:text>
  90. </xsl:when>
  91. <xsl:when test="$type='largebinary'">
  92. <xsl:text>DB1_BLOB</xsl:text>
  93. </xsl:when>
  94. <xsl:when test="$type='text'">
  95. <xsl:text>DB1_BLOB</xsl:text>
  96. </xsl:when>
  97. <xsl:when test="$type='largetext'">
  98. <xsl:text>DB1_BLOB</xsl:text>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:call-template name="type-error"/>
  102. </xsl:otherwise>
  103. </xsl:choose>
  104. </xsl:template>
  105. </xsl:stylesheet>