object_modeling_new.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  5. exclude-result-prefixes="xs"
  6. version="2.0">
  7. <!--<xsl:include href="system_cache__appinfo/TargetNamespaceBindings.xsl"/>-->
  8. <xsl:include href="object_modeling.xsl"/> <!-- to use one time system_cache__appinfo:new_object_by_prototype_schema_root -->
  9. <!--<xsl:param name="new_object_namespace" required="yes"/>--> <!-- example https://biuro.biall-net.pl/wfs/default_db/table/CRM_PROCES.xsd -->
  10. <xsl:param name="TargetNamespaceBindingsApi" required="yes"/> <!-- example https://biuro.biall-net.pl/wfs -->
  11. <xsl:param name="NamespaceDatabaseStorageDefinitionPrefix" select="'default_db'"/> <!-- example default_db -->
  12. <xsl:param name="NamespaceObjectInstanceType" select="'table'"/> <!-- example table -->
  13. <!--<xsl:param name="NamespaceObjectInstanceTable" required="yes"/>--> <!-- example CRM_PROCES -->
  14. <xsl:param name="template_object.xml_location" required="yes"/> <!-- <xsl:variable name="template_object.xml_location" select="concat($object_modeling_new_repository,'/',$NamespaceDatabaseStorageDefinitionPrefix,'/',$NamespaceObjectInstanceType,'/',$NamespaceObjectInstanceTable,'.xml')"/> -->
  15. <xsl:param name="object_modeling_new_basedir_repository" required="yes"/> <!-- location where is template modified objects repository for debug only -->
  16. <!--<xsl:param name="object_modeling.Error.Handling" select="'IGNORE'"/>--> <!-- ERROR / IGNORE / OVERWRITE / MERGE (todo) -->
  17. <!--<xsl:param name="prototype_object_namespace" select="'https://biuro.biall-net.pl/wfs/default_db/Types/Default.xsd'"/>--> <!-- for default prototype object set in child xsl -->
  18. <xsl:variable name="TargetNamespace_from_Bindings">
  19. <!--<xsl:message>#24 debug call system_cache__appinfo:TargetNamespace_from_Bindings with $NamespaceDatabaseStorageDefinitionPrefix = <xsl:value-of select="$NamespaceDatabaseStorageDefinitionPrefix"/>;</xsl:message>-->
  20. <xsl:call-template name="system_cache__appinfo:TargetNamespace_from_Bindings">
  21. <xsl:with-param name="NamespaceDatabaseStorageDefinitionPrefix" select="$NamespaceDatabaseStorageDefinitionPrefix"/>
  22. <xsl:with-param name="NamespaceObjectInstanceTable" select="$NamespaceObjectInstanceTable"/>
  23. <xsl:with-param name="TargetNamespaceBindingsApi" select="$TargetNamespaceBindingsApi"/>
  24. <xsl:with-param name="NamespaceObjectInstanceType" select="$NamespaceObjectInstanceType"/>
  25. </xsl:call-template>
  26. </xsl:variable>
  27. <xsl:variable name="prototype_TargetNamespaceBindings_from_Namespace">
  28. <xsl:call-template name="system_cache__appinfo:TargetNamespaceBindings_from_Namespace">
  29. <xsl:with-param name="TargetNamespace" select="$prototype_object_namespace"/>
  30. </xsl:call-template>
  31. </xsl:variable>
  32. <xsl:variable name="new_TargetNamespaceBindings_from_Namespace">
  33. <xsl:call-template name="system_cache__appinfo:TargetNamespaceBindings_from_Namespace">
  34. <xsl:with-param name="TargetNamespace" select="$TargetNamespace_from_Bindings//@TargetNamespace"/>
  35. </xsl:call-template>
  36. </xsl:variable>
  37. <xsl:variable name="template_object.xml">
  38. <xsl:choose>
  39. <xsl:when test=" doc-available( $template_object.xml_location)">
  40. <xsl:copy-of select=" doc($template_object.xml_location)"></xsl:copy-of>
  41. </xsl:when>
  42. </xsl:choose>
  43. </xsl:variable>
  44. <xsl:template match="system_cache__appinfo:get_all_xsd_list" mode="system_cache__appinfo:object_modeling_new">
  45. <system_cache__appinfo:object_modeling_new>
  46. <xsl:attribute name="object_modeling_new_basedir_repository" select="$object_modeling_new_basedir_repository"/>
  47. <xsl:copy-of select="$TargetNamespace_from_Bindings"/>
  48. <new_TargetNamespaceBindings_from_Namespace>
  49. <xsl:copy-of select="$new_TargetNamespaceBindings_from_Namespace"></xsl:copy-of>
  50. </new_TargetNamespaceBindings_from_Namespace>
  51. <xsl:variable name="system_cache__appinfo:object_modeling_new_test_if_exists">
  52. <xsl:apply-templates mode="system_cache__appinfo:object_modeling_new_test_if_exists"/>
  53. </xsl:variable>
  54. <xsl:choose>
  55. <xsl:when test="$system_cache__appinfo:object_modeling_new_test_if_exists/* and $object_modeling.Error.Handling='ERROR'">
  56. <ERROR>
  57. Object already defined in current schema
  58. </ERROR>
  59. </xsl:when>
  60. <xsl:when test="$system_cache__appinfo:object_modeling_new_test_if_exists/* and $object_modeling.Error.Handling='IGNORE'">
  61. <WARNING>
  62. Object already defined in current schema - but ignoring due to $object_modeling.Error.Handling param set to <xsl:value-of select="$object_modeling.Error.Handling"/>
  63. </WARNING>
  64. </xsl:when>
  65. <xsl:otherwise>
  66. <OK>
  67. We try to create new object in <xsl:value-of select="$template_object.xml_location"/>
  68. </OK>
  69. <xsl:variable name="system_cache__appinfo:new_object_by_prototype_test_if_prototype">
  70. <xsl:apply-templates mode="system_cache__appinfo:new_object_by_prototype_test_if_prototype"/>
  71. </xsl:variable>
  72. <xsl:choose>
  73. <xsl:when test="$system_cache__appinfo:new_object_by_prototype_test_if_prototype/*">
  74. <xsl:apply-templates mode="system_cache__appinfo:object_modeling_new_add"/>
  75. </xsl:when>
  76. <xsl:otherwise>
  77. <!--<xsl:message terminate="yes">#84 prototype <xsl:value-of select="$prototype_object_namespace"/> not exists in schema! if it realy exist consider rebuild procesy5_system_schema.xml !</xsl:message>-->
  78. <system_cache__appinfo:new_object_by_prototype_test_if_prototype>
  79. <xsl:copy-of select="$system_cache__appinfo:new_object_by_prototype_test_if_prototype"/>
  80. </system_cache__appinfo:new_object_by_prototype_test_if_prototype>
  81. <ERROR>Not exists prototype $prototype_object_namespace=<xsl:value-of select="$prototype_object_namespace"/>;</ERROR>
  82. </xsl:otherwise>
  83. </xsl:choose>
  84. </xsl:otherwise>
  85. </xsl:choose>
  86. </system_cache__appinfo:object_modeling_new>
  87. </xsl:template>
  88. <xsl:template mode="system_cache__appinfo:object_modeling_new_add" match="schema[@targetNamespace=$prototype_object_namespace]" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  89. <xsl:result-document href="{$template_object.xml_location}">
  90. <xsl:element name="xs:schema">
  91. <xsl:copy-of select="namespace::node()"/>
  92. <xsl:namespace name="{$new_TargetNamespaceBindings_from_Namespace//@NamespacePrefix}" select="$TargetNamespace_from_Bindings//@TargetNamespace"/>
  93. <xsl:attribute name="targetNamespace" select="$TargetNamespace_from_Bindings//@TargetNamespace"/>
  94. <xsl:variable name="prototype_NamespacePrefix">
  95. <xsl:for-each select="namespace::node()">
  96. <xsl:if test=".= $prototype_object_namespace">
  97. <xsl:value-of select="name()"/>
  98. </xsl:if>
  99. </xsl:for-each>
  100. </xsl:variable>
  101. <xsl:apply-templates mode="system_cache__appinfo:new_object_by_prototype_schema_root">
  102. <xsl:with-param name="prototype_TargetNamespaceBindings_from_Namespace" select="$prototype_TargetNamespaceBindings_from_Namespace"/>
  103. <xsl:with-param name="new_TargetNamespaceBindings_from_Namespace" select="$new_TargetNamespaceBindings_from_Namespace"/>
  104. <xsl:with-param name="prototype_NamespacePrefix" select="$prototype_NamespacePrefix"/>
  105. </xsl:apply-templates>
  106. </xsl:element>
  107. </xsl:result-document>
  108. </xsl:template>
  109. <xsl:template mode="system_cache__appinfo:object_modeling_new_add" match="schema|text()|comment()"/>
  110. <xsl:template match="system_cache__appinfo:get_all_xsd" mode="system_cache__appinfo:object_modeling_new">
  111. <xsl:apply-templates mode="system_cache__appinfo:object_modeling_new_test_if_exists"/>
  112. </xsl:template>
  113. <xsl:template match="system_cache__appinfo:get_all_xsd_list" mode="system_cache__appinfo:object_modeling_new_test_if_exists">
  114. <system_cache__appinfo:object_modeling_new_test_if_exists>
  115. <xsl:message><xsl:copy-of select="$TargetNamespace_from_Bindings//@TargetNamespace"/></xsl:message>
  116. <xsl:apply-templates mode="system_cache__appinfo:object_modeling_new_test_if_exists"/>
  117. </system_cache__appinfo:object_modeling_new_test_if_exists>
  118. </xsl:template>
  119. <xsl:template match="system_cache__appinfo:get_all_xsd" mode="system_cache__appinfo:object_modeling_new_test_if_exists">
  120. <xsl:apply-templates mode="system_cache__appinfo:object_modeling_new_test_if_exists"/>
  121. </xsl:template>
  122. <xsl:template mode="system_cache__appinfo:object_modeling_new_test_if_exists" match="schema[@targetNamespace=$TargetNamespace_from_Bindings//@TargetNamespace]" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  123. <!-- not good - we have some objects already in this schema -->
  124. <!--<xsl:copy-of select="."/>-->
  125. <xsl:choose>
  126. <xsl:when test="$object_modeling.Error.Handling='ERROR'">
  127. <ERROR>
  128. Object already defined in current schema
  129. </ERROR>
  130. </xsl:when>
  131. <xsl:when test="$object_modeling.Error.Handling='IGNORE'">
  132. <WARNING>
  133. Object already defined in current schema - but ignoring due to $object_modeling.Error.Handling param set to <xsl:value-of select="$object_modeling.Error.Handling"/>
  134. </WARNING>
  135. </xsl:when>
  136. <xsl:otherwise>
  137. <ERROR>
  138. Object already defined in current schema
  139. </ERROR>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. <!--<xsl:copy-of select="."/>-->
  143. </xsl:template>
  144. <xsl:template mode="system_cache__appinfo:object_modeling_new_test_if_exists" match="schema" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"/>
  145. <xsl:template mode="system_cache__appinfo:object_modeling_new_add_new_table" match="object_modeling_new_add_new_table">
  146. <system_cache__appinfo:object_modeling_new_add_new_table>
  147. <TargetNamespace_from_Bindings>
  148. <xsl:copy-of select="$TargetNamespace_from_Bindings"/>
  149. </TargetNamespace_from_Bindings>
  150. <new_TargetNamespaceBindings_from_Namespace>
  151. <xsl:copy-of select="$new_TargetNamespaceBindings_from_Namespace"/>
  152. </new_TargetNamespaceBindings_from_Namespace>
  153. <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
  154. xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
  155. xmlns:gml="http://www.opengis.net/gml/3.2"
  156. xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty"
  157. xmlns:default_db__x3A__SALES_PLAN="https://biuro.biall-net.pl/wfs/default_db/table/SALES_PLAN.xsd"
  158. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd">
  159. <xsl:namespace name="{$TargetNamespace_from_Bindings//@Prefix}" select="$TargetNamespace_from_Bindings//@TargetNamespace"/>
  160. <xsl:attribute name="elementFormDefault" select="'qualified'"/>
  161. <xsl:attribute name="targetNamespace" select="$TargetNamespace_from_Bindings//@TargetNamespace"/>
  162. <xsl:if test="$vc:minVersion"><xsl:attribute name="vc:minVersion" select="$vc:minVersion"/></xsl:if>
  163. <xsl:if test="$vc:maxVersion"><xsl:attribute name="vc:maxVersion" select="$vc:maxVersion"/></xsl:if>
  164. <xs:complexType name="{$new_TargetNamespaceBindings_from_Namespace//@NamespaceObjectInstanceTable}">
  165. <xs:sequence />
  166. </xs:complexType>
  167. <xs:element name="{$new_TargetNamespaceBindings_from_Namespace//@NamespaceObjectInstanceTable}">
  168. <xsl:attribute name="type" select="concat($TargetNamespace_from_Bindings//@Prefix,':',$new_TargetNamespaceBindings_from_Namespace//@NamespaceObjectInstanceTable)"/>
  169. </xs:element>
  170. </xs:schema>
  171. </system_cache__appinfo:object_modeling_new_add_new_table>
  172. </xsl:template>
  173. </xsl:stylesheet>