get_all_xsd.xsl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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. exclude-result-prefixes="xs hfp"
  5. version="2.0"
  6. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  7. xmlns:hfp="http://www.w3.org/2001/XMLSchema-hasFacetAndProperty">
  8. <xsl:include href="../default_db_xml_cache.public/xml-schema-primitives.xsl"/>
  9. <xsl:function name="system_cache__appinfo:clean_object_prefix">
  10. <xsl:param name="name" required="yes"/>
  11. <xsl:choose>
  12. <xsl:when test="substring-after($name,':')">
  13. <xsl:value-of select="substring-after($name,':')"/>
  14. </xsl:when>
  15. <xsl:otherwise>
  16. <xsl:value-of select="$name"/>
  17. </xsl:otherwise>
  18. </xsl:choose>
  19. </xsl:function>
  20. <xsl:function name="system_cache__appinfo:get_object_prefix">
  21. <xsl:param name="name" required="yes"/>
  22. <xsl:choose>
  23. <xsl:when test="substring-before($name,':')">
  24. <xsl:value-of select="substring-before($name,':')"/>
  25. </xsl:when>
  26. <xsl:otherwise>
  27. <xsl:message terminate="yes">system_cache__appinfo:get_object_prefix(<xsl:value-of select="$name"/>) - parameter has no exptected prefix:object format definition! Maybe not expected schema?</xsl:message>
  28. </xsl:otherwise>
  29. </xsl:choose>
  30. </xsl:function>
  31. <!-- funkcja do wyczyszczenia wyescapowenago prefixu z np. default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  32. <xsl:function name="system_cache__appinfo:clean_object_escaped_prefix">
  33. <xsl:param name="name" required="yes"/>
  34. </xsl:function>
  35. <!-- funkcja do ponownego zamienienia na sredniki itp z np. default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  36. <xsl:function name="system_cache__appinfo:translate_object_escaped_prefix_from_string">
  37. <xsl:param name="name" required="yes"/>
  38. <xsl:value-of select="replace(replace(replace(replace(replace(replace(replace(replace($name, '__x2F__', '/'), '__x3A__', ':'),'__x2D__','-'),'__x25__','%'),'__x28__','('),'__x29__',')'),'__x23__','#'),'__x2A__','*')"/>
  39. </xsl:function>
  40. <!-- funkcja do zamienienia na postac default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  41. <xsl:function name="system_cache__appinfo:escape_object_prefix_to_string">
  42. <xsl:param name="name" required="yes"/>
  43. <xsl:value-of select="replace(replace(replace(replace(replace(replace(replace(replace($name, '/', '__x2F__'), ':', '__x3A__'),'-','__x2D__'),'%','__x25__'), '\(', '__x28__'), '\)' ,'__x29__'),'#','__x23__'),'\*','__x2A__')"/>
  44. </xsl:function>
  45. <xsl:template name="system_cache__appinfo:prefixed_object_info">
  46. <xsl:param name="prefixed_object" required="yes"/>
  47. <xsl:variable name="prefix_token" select="tokenize(system_cache__appinfo:translate_object_escaped_prefix_from_string($prefixed_object),':')"/>
  48. <system_cache__appinfo:prefixed_object_info>
  49. <xsl:attribute name="prefix" select="$prefix_token[1]"/>
  50. <xsl:attribute name="name" select="$prefix_token[2]"/>
  51. <xsl:attribute name="element" select="$prefix_token[3]"/>
  52. </system_cache__appinfo:prefixed_object_info>
  53. </xsl:template>
  54. <!-- @2016-08 funkcje do wykrywania prefixow, namespace itp itd...
  55. <xsl:attribute name="prefix" select="$vrtfNamespaces/ns[@uri=$targetnamespace][1]/@prefix" xpath-default-namespace=""/>
  56. <xsl:attribute name="targetnamespace" select="$targetnamespace"/>
  57. <xsl:attribute name="type_79" select="$type_79"/>
  58. <xsl:attribute name="prefix_79" select="$prefix_79"/>
  59. <xsl:attribute name="type_79_nopref" select="$type_79_nopref"/>
  60. -->
  61. <xsl:function name="system_cache__appinfo:prefix_from_targetNamespace">
  62. <xsl:param name="system_cache__appinfo:vrtfNamespaces" required="yes"/>
  63. <xsl:param name="targetNamespace" required="yes"/>
  64. <xsl:value-of select="$system_cache__appinfo:vrtfNamespaces/ns[@uri=$targetNamespace][1]/@prefix" xpath-default-namespace=""/>
  65. </xsl:function>
  66. <xsl:function name="system_cache__appinfo:targetNamespace_from_prefix">
  67. <xsl:param name="system_cache__appinfo:vrtfNamespaces" required="yes"/>
  68. <xsl:param name="prefix" required="yes"/>
  69. <xsl:value-of select="$system_cache__appinfo:vrtfNamespaces/ns[@prefix=$prefix][1]/@uri" xpath-default-namespace=""/>
  70. </xsl:function>
  71. <xsl:function name="system_cache__appinfo:get_default_db_obj_url_table_name"><!-- @2016-10 funkcja do wykrywania nazwy tabeli dla default db, w przypadku braku zgodnosci namespace - nic nie zwraca -->
  72. <xsl:param name="parent_complexTypeNamespace" required="yes"/>
  73. <xsl:variable name="uri_tokens" select="tokenize($parent_complexTypeNamespace,'/')"/>
  74. <xsl:variable name="uri_tokens_count" select="count($uri_tokens)"/>
  75. <xsl:if test="$uri_tokens[($uri_tokens_count - 1)]='table' and $uri_tokens[($uri_tokens_count - 2)]='default_db' and $uri_tokens[($uri_tokens_count - 3)]='wfs'">
  76. <xsl:variable name="get_default_db_obj_url_table_name" select="tokenize($uri_tokens[$uri_tokens_count],'\.')"/>
  77. <xsl:value-of select="$get_default_db_obj_url_table_name[1]"/>
  78. </xsl:if>
  79. </xsl:function>
  80. <!--<xsl:function name="system_cache__appinfo:php_function_name_from_obj_with_prefix">
  81. <xsl:param name="object_name" required="yes"/>
  82. <xsl:value-of select="replace($object_name,':','__x3A__')"/>
  83. </xsl:function>-->
  84. <xsl:template name="main">
  85. <xsl:call-template name="system_cache__appinfo:get_all_xsd">
  86. <xsl:with-param name="path2collection" select="'../'"/>
  87. <xsl:with-param name="cache" select="'read'"/>
  88. </xsl:call-template>
  89. </xsl:template>
  90. <xsl:template name="system_cache__appinfo:get_all_xsd">
  91. <xsl:param name="path2collection" select="'../default_objects/'"/>
  92. <xsl:param name="get_system_schemas"/>
  93. <xsl:param name="cache" select="'read'"/>
  94. <xsl:variable name="element-filename" select="'procesy5_system_schema'"/>
  95. <xsl:choose>
  96. <xsl:when test="unparsed-text-available(concat('../default_db.instance.xml/transformed/',$element-filename,'.xml')) and $cache='read'">
  97. <xsl:copy-of select="doc(concat('../default_db.instance.xml/transformed/',$element-filename,'.xml'))"/>
  98. </xsl:when>
  99. <xsl:otherwise>
  100. <xsl:variable name="path">
  101. <xsl:value-of select="concat($path2collection,'?select=*.(xsd);recurse=yes;on-error=warning')"/>
  102. </xsl:variable>
  103. <xsl:variable name="docs" select="collection($path)"/>
  104. <xsl:variable name="procesy5_system_schema">
  105. <system_cache__appinfo:get_all_xsd_list>
  106. <xsl:for-each select="$docs">
  107. <xsl:message> get_all_xsd przetwarzam plik <xsl:value-of select="document-uri(/)"/></xsl:message>
  108. <system_cache__appinfo:get_all_xsd>
  109. <xsl:attribute name="system_cache__appinfo:document-uri" select="substring-after(document-uri(/), '/public_html/')"/>
  110. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="document-uri(/)"/>
  111. <!--<xsl:for-each select="//schema" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  112. <xsl:element name="{name()}">
  113. <xsl:for-each select="@*">
  114. <xsl:attribute name="{name()}" select="."/>
  115. <xsl:copy-of select="child::node()"/>
  116. </xsl:for-each>
  117. </xsl:element>
  118. </xsl:for-each>-->
  119. <xsl:copy-of select="/"/>
  120. </system_cache__appinfo:get_all_xsd>
  121. </xsl:for-each>
  122. <!-- -->
  123. <xsl:message> schemat dla XML primitives <xsl:value-of select="'http://www.w3.org/1999/XSL/Transform'"/></xsl:message>
  124. <system_cache__appinfo:get_all_xsd>
  125. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  126. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  127. <xsl:copy-of select="$system_cache__appinfo:primitives.xsd"/>
  128. </system_cache__appinfo:get_all_xsd>
  129. <xsl:message> schemat dla XML primitives/derived <xsl:value-of select="'http://www.w3.org/1999/XSL/Transform'"/></xsl:message>
  130. <system_cache__appinfo:get_all_xsd>
  131. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  132. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  133. <xsl:copy-of select="$system_cache__appinfo:derived.xsd"/>
  134. </system_cache__appinfo:get_all_xsd>
  135. <system_cache__appinfo:get_all_xsd>
  136. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  137. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  138. <xsl:copy-of select="$system_cache__appinfo:XMLSchema11.xsd"/>
  139. </system_cache__appinfo:get_all_xsd>
  140. <system_cache__appinfo:get_all_xsd>
  141. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  142. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  143. <xsl:copy-of select="$system_cache__appinfo:builtintypes.xsd"/>
  144. </system_cache__appinfo:get_all_xsd>
  145. </system_cache__appinfo:get_all_xsd_list>
  146. </xsl:variable>
  147. <xsl:result-document href="{concat('../default_db.instance.xml/transformed/',$element-filename,'.xml')}">
  148. <xsl:copy-of select="$procesy5_system_schema"/>
  149. </xsl:result-document>
  150. <xsl:copy-of select="$procesy5_system_schema"></xsl:copy-of>
  151. </xsl:otherwise>
  152. </xsl:choose>
  153. </xsl:template>
  154. <xsl:template name="system_cache__appinfo:vrtfNamespaces">
  155. <xsl:variable name="procesy5_system_schema">
  156. <xsl:call-template name="system_cache__appinfo:get_all_xsd">
  157. <xsl:with-param name="path2collection" select="'../'"/>
  158. <xsl:with-param name="cache" select="'read'"></xsl:with-param>
  159. </xsl:call-template>
  160. </xsl:variable>
  161. <xsl:for-each select="$procesy5_system_schema//schema/namespace::node()"
  162. xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  163. <ns element="{name(..)}" prefix="{name()}" uri="{.}"/>
  164. </xsl:for-each>
  165. </xsl:template>
  166. <!-- do aktualizowania pozycji w schemache-->
  167. <xsl:template name="system_cache__appinfo:position">
  168. <xsl:param name="xml"/>
  169. <xsl:for-each select="$xml/*">
  170. <xsl:if test="name()">
  171. <xsl:element name="{name()}">
  172. <xsl:attribute name="system_cache__appinfo:position" select="position()"/>
  173. <xsl:apply-templates mode="system_cache__appinfo:position" select="@*"/>
  174. <xsl:call-template name="system_cache__appinfo:position">
  175. <xsl:with-param name="xml" select="."/>
  176. </xsl:call-template>
  177. </xsl:element>
  178. </xsl:if>
  179. </xsl:for-each>
  180. </xsl:template>
  181. <xsl:template match="@*" mode="system_cache__appinfo:position">
  182. <xsl:attribute name="{name()}" select="."/>
  183. </xsl:template>
  184. <xsl:template match="text()" mode="system_cache__appinfo:position"/>
  185. <xsl:template match="comment()" mode="system_cache__appinfo:position"/>
  186. </xsl:stylesheet>