schema_maintain.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  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:vc="http://www.w3.org/2007/XMLSchema-versioning"
  5. exclude-result-prefixes="vc"
  6. version="2.0"
  7. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  8. xmlns:system_cache__appinfo_schema_maintain="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/system_cache__appinfo_schema_maintain.xsd"
  9. xmlns:system_cache__resources_tree_generate_xsl_required_occurs_raport="http://biuro.biall-net.pl/xmlschema_procesy5/system_cache/resources_tree_generate_xsl_require_occurs_raport"
  10. xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty">
  11. <!-- @2017-02 bindera: templaty do weryfikacji poprawnosci bazy danych ze schematami - to weryfikacji przydatnosci -->
  12. <xsl:import href="resources_tree_generate_xsl_require_occurs_raport.xsl"/>
  13. <xsl:include href="../default_db_xml_cache.public/xml-schema-primitives.xsl"/>
  14. <xsl:template name="main">
  15. <xsl:variable name="element_to_verify_schema_base">
  16. <xs:sequence>
  17. <xs:sequence minOccurs="0">
  18. <xs:element minOccurs="0" name="a1"/>
  19. </xs:sequence>
  20. <xs:sequence/>
  21. <xs:element minOccurs="0" name="a"/>
  22. <xs:sequence>
  23. <xs:element name="aa"/>
  24. <xs:element name="aab"/>
  25. </xs:sequence>
  26. <xs:element minOccurs="0" name="b"/>
  27. </xs:sequence>
  28. </xsl:variable>
  29. <xsl:variable name="element_to_verify_schema_restr">
  30. <xs:sequence>
  31. <xs:sequence>
  32. <xs:element name="aa"/>
  33. <xs:element name="aab"/>
  34. </xs:sequence>
  35. <xs:element name="b"/>
  36. </xs:sequence>
  37. </xsl:variable>
  38. <xsl:variable name="analized_base">
  39. <xsl:apply-templates select="$element_to_verify_schema_base" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do"/>
  40. </xsl:variable>
  41. <xsl:result-document href="../default_db.instance.xml/schema_maintain_temp/element_to_verify_schema_base_1.xml">
  42. <system_cache__appinfo_schema_maintain:schema_restriction_validate>
  43. <xsl:copy-of select="$analized_base"/>
  44. </system_cache__appinfo_schema_maintain:schema_restriction_validate>
  45. </xsl:result-document>
  46. <xsl:variable name="analized_restr">
  47. <xsl:apply-templates select="$element_to_verify_schema_restr" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do"/>
  48. </xsl:variable>
  49. <xsl:result-document href="../default_db.instance.xml/schema_maintain_temp/element_to_verify_schema_restr_2.xml">
  50. <system_cache__appinfo_schema_maintain:schema_restriction_validate>
  51. <xsl:copy-of select="$analized_restr"/>
  52. </system_cache__appinfo_schema_maintain:schema_restriction_validate>
  53. </xsl:result-document>
  54. <xsl:variable name="system_cache__appinfo_schema_maintain:analyze_base_to_restr">
  55. <system_cache__appinfo_schema_maintain:analyze_base_to_restr>
  56. <xsl:call-template name="system_cache__appinfo_schema_maintain:analyze_base_to_restr">
  57. <xsl:with-param name="analized_base" select="$analized_base"/>
  58. <xsl:with-param name="analized_restr" select="$analized_restr"/>
  59. </xsl:call-template>
  60. </system_cache__appinfo_schema_maintain:analyze_base_to_restr>
  61. </xsl:variable>
  62. <xsl:result-document href="../default_db.instance.xml/schema_maintain_temp/analyze_base_to_restr_3.xml">
  63. <xsl:copy-of select="$system_cache__appinfo_schema_maintain:analyze_base_to_restr"/>
  64. </xsl:result-document>
  65. </xsl:template>
  66. <!-- pomysl na zbudowanie widoku wyplaszczonego widoku elementu aby moc porownac czy jest na nim prawidlowa restrykcja do innego podobnego -->
  67. <!--<xsl:template match="sequence" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  68. <xsl:element name="{name()}" >
  69. <xsl:attribute name="minOccurs" select="system_cache__appinfo:schema_occurs_max_sequence(@minOccurs)"/>
  70. <xsl:attribute name="maxOccurs" select="system_cache__appinfo:schema_occurs_max_sequence(@maxOccurs)"/>
  71. <xsl:apply-templates select="@*" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do_attr"/>
  72. </xsl:element>
  73. <xsl:apply-templates mode="#current"/>
  74. </xsl:template>-->
  75. <xsl:template name="system_cache__appinfo_schema_maintain:analyze_base_to_restr">
  76. <xsl:param name="analized_base" required="yes"/>
  77. <xsl:param name="analized_restr" required="yes"/>
  78. <!-- szukamy wezla do przejechania podobnego do base oraz restr -->
  79. <xsl:for-each select="$analized_base">
  80. </xsl:for-each>
  81. </xsl:template>
  82. <xsl:template match="*" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do">
  83. <xsl:param name="xpath" select="''"/>
  84. <xsl:variable name="xpath_name">
  85. <xsl:if test="name()">element:<xsl:value-of select="name()"/>;</xsl:if>
  86. <xsl:if test="@name">name:<xsl:value-of select="@name"/>;</xsl:if>
  87. <xsl:if test="@name">ref:<xsl:value-of select="@ref"/>;</xsl:if>
  88. </xsl:variable>
  89. <xsl:variable name="xpath_name" select="concat($xpath,'/',$xpath_name)"/>
  90. <xsl:element name="{name()}" >
  91. <xsl:attribute name="xpath_name" select="$xpath_name"/>
  92. <xsl:attribute name="minOccurs" select="system_cache__appinfo:schema_occurs_max_sequence(@minOccurs)"/>
  93. <xsl:attribute name="maxOccurs" select="system_cache__appinfo:schema_occurs_max_sequence(@maxOccurs)"/>
  94. <xsl:choose>
  95. <xsl:when test="@name"><xsl:attribute name="name" select="@name"/></xsl:when>
  96. <xsl:when test="@ref"><xsl:attribute name="ref" select="@ref"/></xsl:when>
  97. <xsl:otherwise>
  98. <xsl:if test="@type"><xsl:attribute name="type" select="@type"/></xsl:if></xsl:otherwise>
  99. </xsl:choose>
  100. <!--<xsl:apply-templates select="@*" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do_attr"/>-->
  101. <xsl:choose>
  102. <xsl:when test="name()='choice'">
  103. <xsl:apply-templates mode="#current" >
  104. <xsl:with-param name="xpath" select="$xpath_name"/>
  105. </xsl:apply-templates>
  106. </xsl:when>
  107. <xsl:otherwise>
  108. <xsl:apply-templates mode="#current" >
  109. <xsl:with-param name="xpath" select="$xpath_name"/>
  110. </xsl:apply-templates>
  111. </xsl:otherwise>
  112. </xsl:choose>
  113. </xsl:element>
  114. </xsl:template>
  115. <xsl:template match="@*" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do_attr"/>
  116. <xsl:template match="simpleType" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"/>
  117. <xsl:template match="annotation" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"/>
  118. <xsl:template match="text()|comment()" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate_do"/>
  119. <xsl:template match="text()|comment()" mode="system_cache__appinfo_schema_maintain:schema_restriction_validate"/>
  120. <xsl:template name="system_cache__appinfo_schema_maintain:schema_maintain__append_schema">
  121. <!-- do stworzenia nowego naglowka schema -->
  122. <xsl:param name="targetNamespace" required="yes"/>
  123. <xsl:param name="prefix" required="yes"/>
  124. <xsl:param name="file_href" required="yes"/><!-- link z nazwa pliku do ktorego bedzie akcja-->
  125. <xsl:param name="schema" required="yes"/><!-- zawartosc do dodania -->
  126. <xsl:param name="vrtfNamespaces" required="yes"/><!-- do dolaczenia include schematow, prefixow, jakie sa uzywane-->
  127. <xsl:param name="procesy5_system_schema" required="yes"/>
  128. <xsl:param name="main_targetNamespace" required="yes"/>
  129. <xsl:variable name="schema_to_save">
  130. <system_cache__appinfo:get_all_xsd>
  131. <xsl:element name="{concat(system_cache__appinfo:prefix_from_targetNamespace($vrtfNamespaces,'http://www.w3.org/2001/XMLSchema'),':schema')}" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  132. <xsl:namespace name="{$prefix}" select="$targetNamespace"/>
  133. <xsl:namespace name="vc" select="'http://www.w3.org/2007/XMLSchema-versioning'"/>
  134. <xsl:attribute name="targetNamespace" select="$targetNamespace"/>
  135. <xsl:attribute name="elementFormDefault" select="'qualified'"/>
  136. <xsl:if test="$vc:minVersion"><xsl:attribute name="vc:minVersion" select="$vc:minVersion"/></xsl:if>
  137. <xsl:if test="$vc:maxVersion"><xsl:attribute name="vc:maxVersion" select="$vc:maxVersion"/></xsl:if>
  138. <xsl:for-each select="$schema/namespace::node()">
  139. <xsl:namespace name="{name()}" select="."/>
  140. </xsl:for-each>
  141. <!-- rejestracja prefixu dla main_schematu -->
  142. <xsl:namespace name="{system_cache__appinfo:prefix_from_targetNamespace($vrtfNamespaces,$main_targetNamespace)}" select="$main_targetNamespace"/>
  143. <!-- namespace dla importow rejestracja -->
  144. <xsl:for-each select="$procesy5_system_schema/system_cache__appinfo:get_all_xsd_list/system_cache__appinfo:get_all_xsd/schema[@targetNamespace=$main_targetNamespace]/import" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  145. <xsl:namespace name="{system_cache__appinfo:prefix_from_targetNamespace($vrtfNamespaces,@namespace)}" select="@namespace"/>
  146. </xsl:for-each>
  147. <!--<ns>
  148. <xsl:copy-of select="$vrtfNamespaces"/>
  149. </ns>-->
  150. <!--<schemata>
  151. <xsl:copy-of select="$procesy5_system_schema"/>
  152. </schemata>-->
  153. <!-- import main -->
  154. <xsl:element name="{concat(system_cache__appinfo:prefix_from_targetNamespace($vrtfNamespaces,'http://www.w3.org/2001/XMLSchema'),':import')}">
  155. <xsl:attribute name="namespace" select="$main_targetNamespace"/>
  156. <xsl:attribute name="schemaLocation" select="concat('../',$procesy5_system_schema/system_cache__appinfo:get_all_xsd_list/system_cache__appinfo:get_all_xsd[child::node()/@targetNamespace=$main_targetNamespace]/@system_cache__appinfo:document-uri)"/>
  157. </xsl:element>
  158. <!-- importy -->
  159. <xsl:for-each select="$procesy5_system_schema/system_cache__appinfo:get_all_xsd_list/system_cache__appinfo:get_all_xsd/schema[@targetNamespace=$main_targetNamespace]/import" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  160. <xsl:element name="{name()}">
  161. <xsl:variable name="namespace" select="@namespace"/>
  162. <xsl:attribute name="namespace" select="@namespace"/>
  163. <xsl:attribute name="schemaLocation" select="concat('../',$procesy5_system_schema/system_cache__appinfo:get_all_xsd_list/system_cache__appinfo:get_all_xsd[child::node()/@targetNamespace=$namespace]/@system_cache__appinfo:document-uri)"/>
  164. </xsl:element>
  165. </xsl:for-each>
  166. <xsl:copy-of select="$schema" copy-namespaces="no"/>
  167. </xsl:element>
  168. </system_cache__appinfo:get_all_xsd>
  169. </xsl:variable>
  170. <xsl:variable name="schema_id">
  171. <xsl:apply-templates select="$schema_to_save" mode="system_cache__resources_tree_generate_xsl_required_occurs_raport:generate_element_id_for_schema"/>
  172. </xsl:variable>
  173. <xsl:result-document href="{$file_href}">
  174. <xsl:copy-of select="$schema_id" />
  175. </xsl:result-document>
  176. <!--<xsl:result-document href="{concat($file_href,'_noid.xsd')}">
  177. <xsl:copy-of select="$schema_to_save/system_cache__appinfo:get_all_xsd/*" />
  178. </xsl:result-document>-->
  179. </xsl:template>
  180. </xsl:stylesheet>