get_all_xsd.xsl 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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:output indent="yes"/>
  9. <xsl:strip-space elements="*"/>
  10. <xsl:param name="procesy5_system_schema" select="'../default_db.instance.xml/transformed/procesy5_system_schema.xml'"/>
  11. <xsl:param name="procesy5_system_schema_collection_dir" select="'../'"/>
  12. <xsl:param name="cache" select="'refresh'"/>
  13. <xsl:param name="targetNamespace_DEFAULTS" select="'http://biuro.biall-net.pl/xmlschema_procesy5/default_db'"/>
  14. <xsl:include href="../default_db_xml_cache.public/xml-schema-primitives.xsl"/>
  15. <xsl:function name="system_cache__appinfo:clean_object_prefix">
  16. <xsl:param name="name" required="yes"/>
  17. <xsl:choose>
  18. <xsl:when test="substring-after($name,':')">
  19. <xsl:value-of select="substring-after($name,':')"/>
  20. </xsl:when>
  21. <xsl:otherwise>
  22. <xsl:value-of select="$name"/>
  23. </xsl:otherwise>
  24. </xsl:choose>
  25. </xsl:function>
  26. <xsl:function name="system_cache__appinfo:get_object_prefix">
  27. <xsl:param name="name" required="yes"/>
  28. <xsl:choose>
  29. <xsl:when test="substring-before($name,':')">
  30. <xsl:value-of select="substring-before($name,':')"/>
  31. </xsl:when>
  32. <xsl:otherwise>
  33. <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>
  34. </xsl:otherwise>
  35. </xsl:choose>
  36. </xsl:function>
  37. <!-- funkcja do wyczyszczenia wyescapowenago prefixu z np. default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  38. <xsl:function name="system_cache__appinfo:clean_object_escaped_prefix">
  39. <xsl:param name="name" required="yes"/>
  40. </xsl:function>
  41. <!-- funkcja do ponownego zamienienia na sredniki itp z np. default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  42. <xsl:function name="system_cache__appinfo:translate_object_escaped_prefix_from_string">
  43. <xsl:param name="name" required="yes"/>
  44. <xsl:value-of select="replace(replace(replace(replace(replace(replace(replace(replace($name, '__x2F__', '/'), '__x3A__', ':'),'__x2D__','-'),'__x25__','%'),'__x28__','('),'__x29__',')'),'__x23__','#'),'__x2A__','*')"/>
  45. </xsl:function>
  46. <!-- funkcja do zamienienia na postac default_db__x3A__IN7_DZIENNIK_KORESP do IN7_DZIENNIK_KORESP -->
  47. <xsl:function name="system_cache__appinfo:escape_object_prefix_to_string">
  48. <xsl:param name="name" required="yes"/>
  49. <xsl:value-of select="replace(replace(replace(replace(replace(replace(replace(replace($name, '/', '__x2F__'), ':', '__x3A__'),'-','__x2D__'),'%','__x25__'), '\(', '__x28__'), '\)' ,'__x29__'),'#','__x23__'),'\*','__x2A__')"/>
  50. </xsl:function>
  51. <xsl:template name="system_cache__appinfo:prefixed_object_info">
  52. <xsl:param name="prefixed_object" required="yes"/>
  53. <xsl:variable name="prefix_token" select="tokenize(system_cache__appinfo:translate_object_escaped_prefix_from_string($prefixed_object),':')"/>
  54. <xsl:choose>
  55. <xsl:when test=" string-length($prefix_token[3]) &gt; 0">
  56. <system_cache__appinfo:prefixed_object_info>
  57. <xsl:attribute name="prefix" select="$prefix_token[1]"/>
  58. <xsl:attribute name="name" select="$prefix_token[2]"/>
  59. <xsl:attribute name="element" select="$prefix_token[3]"/>
  60. </system_cache__appinfo:prefixed_object_info>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <system_cache__appinfo:prefixed_object_info>
  64. <xsl:attribute name="prefix" select="$prefix_token[1]"/>
  65. <xsl:attribute name="name" select="$prefix_token[2]"/>
  66. <xsl:attribute name="element" select="$prefix_token[2]"/>
  67. </system_cache__appinfo:prefixed_object_info>
  68. </xsl:otherwise>
  69. </xsl:choose>
  70. </xsl:template>
  71. <!-- @2016-08 funkcje do wykrywania prefixow, namespace itp itd...
  72. <xsl:attribute name="prefix" select="$vrtfNamespaces/ns[@uri=$targetnamespace][1]/@prefix" xpath-default-namespace=""/>
  73. <xsl:attribute name="targetnamespace" select="$targetnamespace"/>
  74. <xsl:attribute name="type_79" select="$type_79"/>
  75. <xsl:attribute name="prefix_79" select="$prefix_79"/>
  76. <xsl:attribute name="type_79_nopref" select="$type_79_nopref"/>
  77. -->
  78. <xsl:function name="system_cache__appinfo:prefix_from_targetNamespace">
  79. <xsl:param name="system_cache__appinfo:vrtfNamespaces" required="yes"/>
  80. <xsl:param name="targetNamespace" required="yes"/>
  81. <xsl:value-of select="$system_cache__appinfo:vrtfNamespaces/ns[@uri=$targetNamespace][1]/@prefix" xpath-default-namespace=""/>
  82. </xsl:function>
  83. <xsl:function name="system_cache__appinfo:targetNamespace_from_prefix">
  84. <xsl:param name="system_cache__appinfo:vrtfNamespaces" required="yes"/>
  85. <xsl:param name="prefix" required="yes"/>
  86. <xsl:value-of select="$system_cache__appinfo:vrtfNamespaces//ns[@prefix=$prefix][1]/@uri" xpath-default-namespace=""/>
  87. </xsl:function>
  88. <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 -->
  89. <xsl:param name="parent_complexTypeNamespace" required="yes"/>
  90. <xsl:variable name="uri_tokens" select="tokenize($parent_complexTypeNamespace,'/')"/>
  91. <xsl:variable name="uri_tokens_count" select="count($uri_tokens)"/>
  92. <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'">
  93. <xsl:variable name="get_default_db_obj_url_table_name" select="tokenize($uri_tokens[$uri_tokens_count],'\.')"/>
  94. <xsl:value-of select="$get_default_db_obj_url_table_name[1]"/>
  95. </xsl:if>
  96. </xsl:function>
  97. <!--<xsl:function name="system_cache__appinfo:php_function_name_from_obj_with_prefix">
  98. <xsl:param name="object_name" required="yes"/>
  99. <xsl:value-of select="replace($object_name,':','__x3A__')"/>
  100. </xsl:function>-->
  101. <xsl:template name="main">
  102. <xsl:call-template name="system_cache__appinfo:get_all_xsd">
  103. <xsl:with-param name="path2collection" select="'../'"/>
  104. <xsl:with-param name="cache" select="'read'"/>
  105. </xsl:call-template>
  106. </xsl:template>
  107. <xsl:template name="system_cache__appinfo:get_all_xsd">
  108. <xsl:param name="path2collection" select="$procesy5_system_schema_collection_dir"/>
  109. <xsl:param name="get_system_schemas"/>
  110. <xsl:param name="cache" select="$cache"/>
  111. <xsl:variable name="element-filename" select="'procesy5_system_schema'"/>
  112. <xsl:choose>
  113. <xsl:when test="unparsed-text-available(concat('../default_db.instance.xml/transformed/',$element-filename,'.xml')) and $cache='read'">
  114. <xsl:copy-of select="doc(concat('../default_db.instance.xml/transformed/',$element-filename,'.xml'))"/>
  115. </xsl:when>
  116. <xsl:otherwise>
  117. <xsl:variable name="path">
  118. <xsl:value-of select="concat($path2collection,'?select=*.(xsd);recurse=yes;on-error=warning')"/>
  119. </xsl:variable>
  120. <xsl:variable name="docs" select="collection($path)"/>
  121. <xsl:variable name="procesy5_system_schema">
  122. <system_cache__appinfo:get_all_xsd_list>
  123. <xsl:for-each select="$docs">
  124. <xsl:message> get_all_xsd przetwarzam plik <xsl:value-of select="document-uri(/)"/></xsl:message>
  125. <system_cache__appinfo:get_all_xsd>
  126. <xsl:attribute name="system_cache__appinfo:document-uri" select="substring-after(document-uri(/), '/public_html/')"/>
  127. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="document-uri(/)"/>
  128. <!--<xsl:for-each select="//schema" xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  129. <xsl:element name="{name()}">
  130. <xsl:for-each select="@*">
  131. <xsl:attribute name="{name()}" select="."/>
  132. <xsl:copy-of select="child::node()"/>
  133. </xsl:for-each>
  134. </xsl:element>
  135. </xsl:for-each>-->
  136. <xsl:copy-of select="/"/>
  137. </system_cache__appinfo:get_all_xsd>
  138. </xsl:for-each>
  139. <!-- -->
  140. <xsl:message> schemat dla XML primitives <xsl:value-of select="'http://www.w3.org/1999/XSL/Transform'"/></xsl:message>
  141. <system_cache__appinfo:get_all_xsd>
  142. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  143. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  144. <xsl:copy-of select="$system_cache__appinfo:primitives.xsd"/>
  145. </system_cache__appinfo:get_all_xsd>
  146. <xsl:message> schemat dla XML primitives/derived <xsl:value-of select="'http://www.w3.org/1999/XSL/Transform'"/></xsl:message>
  147. <system_cache__appinfo:get_all_xsd>
  148. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  149. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  150. <xsl:copy-of select="$system_cache__appinfo:derived.xsd"/>
  151. </system_cache__appinfo:get_all_xsd>
  152. <system_cache__appinfo:get_all_xsd>
  153. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  154. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  155. <xsl:copy-of select="$system_cache__appinfo:XMLSchema11.xsd"/>
  156. </system_cache__appinfo:get_all_xsd>
  157. <system_cache__appinfo:get_all_xsd>
  158. <xsl:attribute name="system_cache__appinfo:document-uri" select="'http://www.w3.org/1999/XSL/Transform'"/>
  159. <xsl:attribute name="system_cache__appinfo:document-uri-full" select="'http://www.w3.org/1999/XSL/Transform'"/>
  160. <xsl:copy-of select="$system_cache__appinfo:builtintypes.xsd"/>
  161. </system_cache__appinfo:get_all_xsd>
  162. </system_cache__appinfo:get_all_xsd_list>
  163. </xsl:variable>
  164. <!--<xsl:result-document href="{concat('../default_db.instance.xml/transformed/',$element-filename,'.xml')}">
  165. <xsl:copy-of select="$procesy5_system_schema"/>
  166. </xsl:result-document>-->
  167. <xsl:copy-of select="$procesy5_system_schema"></xsl:copy-of>
  168. </xsl:otherwise>
  169. </xsl:choose>
  170. </xsl:template>
  171. <xsl:template name="system_cache__appinfo:vrtfNamespaces">
  172. <xsl:variable name="procesy5_system_schema">
  173. <xsl:call-template name="system_cache__appinfo:get_all_xsd">
  174. <xsl:with-param name="path2collection" select="$procesy5_system_schema_collection_dir"/>
  175. <xsl:with-param name="cache" select="'read'"/>
  176. </xsl:call-template>
  177. </xsl:variable>
  178. <xsl:for-each select="$procesy5_system_schema//schema/namespace::node()"
  179. xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  180. <ns element="{name(..)}" prefix="{name()}" uri="{.}"/>
  181. </xsl:for-each>
  182. </xsl:template>
  183. <xsl:template match="system_cache__appinfo:get_all_xsd_list" mode="system_cache__appinfo:vrtfNamespaces">
  184. <system_cache__appinfo:vrtfNamespaces>
  185. <xsl:for-each select="//schema/namespace::node()"
  186. xpath-default-namespace="http://www.w3.org/2001/XMLSchema">
  187. <ns element="{name(..)}" prefix="{name()}" uri="{.}"/>
  188. </xsl:for-each>
  189. </system_cache__appinfo:vrtfNamespaces>
  190. </xsl:template>
  191. <xsl:template match="system_cache__appinfo:get_all_xsd_list" mode="system_cache__appinfo:element_complexType">
  192. <xsl:param name="targetNamespace" select="$targetNamespace_DEFAULTS"/>
  193. <system_cache__appinfo:element_complexType>
  194. <xsl:for-each select="get_all_xsd[ substring-before(@system_cache__appinfo:document-uri,'/')!='default_db_xml_cache' and substring-before(@system_cache__appinfo:document-uri,'/')!='default_db_xml_cache.public']" xpath-default-namespace="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd">
  195. <xsl:variable name="get_all_xsd_236" select="."/>
  196. <xsl:comment>
  197. 246:detect_resource_type, przetwarzam schemat:<xsl:value-of select="@system_cache__appinfo:document-uri"/>; $targetNamespace:<xsl:value-of select="$targetNamespace"/>;
  198. @targetNamespace:<xsl:value-of select="schema/@targetNamespace" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"/>;</xsl:comment>
  199. <xsl:variable name="schema_node_144" select="."/>
  200. <xsl:for-each select="schema" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"><!--[ @targetNamespace != $targetNamespace ] namespace::node() = $targetNamespace and @targetNamespace='moj_ogrodek' -->
  201. <xsl:message>239::detect_resource_type przetwarzam schemat:@targetNamespace:<xsl:value-of select="@targetNamespace"/>;</xsl:message>
  202. <xsl:variable name="prefix_83" select="namespace::node()[. = $targetNamespace]/name()"/>
  203. <xsl:variable name="targetNamespace_134" select="@targetNamespace"/>
  204. <xsl:variable name="prefix_134" select="namespace::node()[. = $targetNamespace_134][1]/name()"/><!-- np. test_objects -->
  205. <xsl:if test="not(@targetNamespace) or not($prefix_134) ">
  206. <xsl:message terminate="yes">#394 ERROR - schema error - set @targetNamespace and prefix for shema file:<xsl:value-of select="../@system_cache__appinfo:document-uri-full"/> ; </xsl:message>
  207. </xsl:if>
  208. <xsl:if test="count(.//node()[(local-name()='element' or local-name()='complexType' or local-name()='sequence' or local-name()='choice' or local-name()='complexContent' or local-name()='extension' ) and not(@id)])=0">
  209. <xsl:for-each select="(element|complexType)" xpath-default-namespace="http://www.w3.org/2001/XMLSchema"><!-- dla ograniczenia mozna [$prefix_134='test_objects']-->
  210. <xsl:variable name="complexType_or_element_name186">
  211. <xsl:choose>
  212. <xsl:when test="local-name()='element'"><xsl:value-of select="@name"/></xsl:when>
  213. <xsl:when test="local-name()='complexType'"><xsl:value-of select="@name"/></xsl:when>
  214. <xsl:otherwise><xsl:message terminate="yes">#391 it should work only for element or complexType</xsl:message></xsl:otherwise>
  215. </xsl:choose>
  216. </xsl:variable>
  217. <xsl:comment>157: buduje plaski obiekt/mape przetwarzania w celu przeszukania relacji @id:<xsl:value-of select="@id"/>; targetNamespace:<xsl:value-of select="$prefix_134"/>; $complexType_or_element_name186:<xsl:value-of select="$complexType_or_element_name186"/>; name:<xsl:value-of select="@name"/>; namespace-uri-for-prefix:<xsl:value-of select="namespace-uri-for-prefix($prefix_134,.)"/></xsl:comment>
  218. <xsl:message>157: buduje plaski obiekt/mape przetwarzania w celu przeszukania relacji @id:<xsl:value-of select="@id"/>; targetNamespace:<xsl:value-of select="$prefix_134"/>; $complexType_or_element_name186:<xsl:value-of select="$complexType_or_element_name186"/>; name:<xsl:value-of select="@name"/>; namespace-uri-for-prefix:<xsl:value-of select="namespace-uri-for-prefix($prefix_134,.)"/></xsl:message>
  219. <xsl:choose>
  220. <xsl:when test="local-name()='element'">
  221. <build_cache name="build_element">
  222. <with-param name="element" select="{$prefix_134}:{$complexType_or_element_name186}"/>
  223. </build_cache>
  224. </xsl:when>
  225. <xsl:when test="local-name()='complexType'">
  226. <build_cache name="build_complexType">
  227. <with-param name="complexType"
  228. select="{$prefix_134}:{$complexType_or_element_name186}"/>
  229. </build_cache>
  230. </xsl:when>
  231. </xsl:choose>
  232. </xsl:for-each>
  233. </xsl:if>
  234. </xsl:for-each>
  235. </xsl:for-each>
  236. </system_cache__appinfo:element_complexType>
  237. </xsl:template>
  238. <!-- do aktualizowania pozycji w schemache-->
  239. <xsl:template name="system_cache__appinfo:position">
  240. <xsl:param name="xml"/>
  241. <xsl:for-each select="$xml/*">
  242. <xsl:if test="name()">
  243. <xsl:element name="{name()}">
  244. <xsl:attribute name="system_cache__appinfo:position" select="position()"/>
  245. <xsl:apply-templates mode="system_cache__appinfo:position" select="@*"/>
  246. <xsl:call-template name="system_cache__appinfo:position">
  247. <xsl:with-param name="xml" select="."/>
  248. </xsl:call-template>
  249. </xsl:element>
  250. </xsl:if>
  251. </xsl:for-each>
  252. </xsl:template>
  253. <xsl:template match="@*" mode="system_cache__appinfo:position">
  254. <xsl:attribute name="{name()}" select="."/>
  255. </xsl:template>
  256. <xsl:template match="text()" mode="system_cache__appinfo:position"/>
  257. <xsl:template match="comment()" mode="system_cache__appinfo:position"/>
  258. </xsl:stylesheet>