grapht.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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"
  5. xmlns:grapht="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/graph_tree/graph_tree.xsd"
  6. xmlns:get_wfs_recurse_xsl="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/get_wfs_recurse_xsl.xsd"
  7. xmlns:y="http://www.yworks.com/xml/graphml"
  8. xmlns:wfs="http://www.opengis.net/wfs"
  9. xmlns:gml="http://www.opengis.net/gml"
  10. xmlns:xlink="http://www.w3.org/1999/xlink"
  11. xmlns:p5="https://biuro.biall-net.pl/wfs"
  12. xmlns:default_db__x3A__BI_audit_ENERGA_PRACOWNICY="https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_PRACOWNICY"
  13. xmlns:default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI="https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI"
  14. xmlns:default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row="https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row"
  15. xmlns:default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object="https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object"
  16. xmlns:default_db__x3A__BI_audit_taxpayer="https://biuro.biall-net.pl/wfs/default_db/BI_audit_taxpayer"
  17. xmlns:default_db__x3A__TERYT_adresy="https://biuro.biall-net.pl/wfs/default_db/TERYT_adresy"
  18. xmlns:default_db__x3A__BI_audit_KRS="https://biuro.biall-net.pl/wfs/default_db/BI_audit_KRS"
  19. xmlns:default_db__x3A__BI_audit_KRS_person="https://biuro.biall-net.pl/wfs/default_db/BI_audit_KRS_person"
  20. xmlns:default_db__x3A__BI_audit_KRS_company="https://biuro.biall-net.pl/wfs/default_db/BI_audit_KRS_company"
  21. xmlns:default_db__x3A__BI_audit_MSIG="https://biuro.biall-net.pl/wfs/default_db/BI_audit_MSIG"
  22. xmlns:default_db__x3A__BI_audit_MSIG_person="https://biuro.biall-net.pl/wfs/default_db/BI_audit_MSIG_person"
  23. xmlns:default_db__x3A__BI_audit_MSIG_company="https://biuro.biall-net.pl/wfs/default_db/BI_audit_MSIG_company"
  24. xmlns:default_db__x3A__BI_audit_MSIG_name="https://biuro.biall-net.pl/wfs/default_db/BI_audit_MSIG_name"
  25. version="2.0">
  26. <xsl:output indent="yes"/>
  27. <xsl:strip-space elements="*"/>
  28. <xsl:template match="get_wfs_recurse_xsl:context.PRIMARYKEY|get_wfs_recurse_xsl:nodes" mode="#all"/>
  29. <xsl:param name="debug.filter" select="'(9177)|(9177)'"/>
  30. <!--
  31. założenia:
  32. - graf ma max głębokość $maxDeepth -
  33. - w zależności od $maxDeepth, tyle razy się powiązuje rekursywnie wszystkie @xlinki, aby wyliczyć długości ścieżek do wszystkich węzłów.
  34. - wyzwolenie liczenia powiązań do wszystkich ścieżek wyzwalamy od jakiegos poziomu do szczytu $currentStartDeepth,
  35. tyle razy dokladamy rekursywnie @xlink, aby osiągnąć $maxDeepth ($toTraverseDeept = $maxDeepth - $currentStartDeepth)
  36. - todo kierunkowe relacje na razie ignorujemy (@backReffed), do rozwazenia implementacji w obliczeniach aby nie liczyc sciezek,
  37. dotyczących relacji przebiegajacych przez backreffy - pytanie w jakich jest to zaleznosciach - do przeanalizowania
  38. - szukamy zawsze listy elementow, dla każdego elementu:
  39. - w górę
  40. - w dół
  41. - @grapht:ancestor.path.len = dlugosc pomiedzy parentem i dzieckiem = $grapht:parent.ancestor.count - $grapht:ancestor.count w elemencie grapht:analyze_nodes.tree.ancestors
  42. - drugie przetworzenie umożliwi znalezienie tras pomiedzy elementami suma z gory + kawalek do gory - bierzemy ktory krótszy
  43. -->
  44. <!--
  45. a.binder Metody optumalizacji wizualizacji danych do weryfikacji czy są gotowe funckje/biblioteki do tego
  46. 1) NearestMiddleShortcut
  47. A - B - C => A - - - C
  48. 2) MiddlePathShortcut
  49. A - B - C - D => A - - - D
  50. 3) MiddleGroup
  51. - C1 - D1 / - D1
  52. A - B + => A [B: C1,C2 ] -
  53. - C2 - D2 \ - D2
  54. 4) CutPath
  55. A - B - C - D => C - D
  56. 5) TypesGroup
  57. A1 - B1 - C1
  58. A2 - B2 - C2 => [ A1, A2, A3 ] = [ B1, B2, B3 ] = [ C1, C2, C3 ]
  59. A3 - B3 - C3
  60. 6) TypesAndFlowsGroup
  61. [ ] - - - - - - [ ]
  62. A1 - B1 - C1 [ A1 ] [ B1 ]- - [ C1 ]
  63. C2 - B2 - A2 => [ B2 ]- - [ A2 ] [ C3 ]
  64. B3 - A3 - C3 [ B3 ] [ A3 ]
  65. mixing this types also
  66. -->
  67. <xsl:function name="wfs:primary_key">
  68. <xsl:param name="xlink:href"/>
  69. <xsl:variable name="tokens" select="count(tokenize($xlink:href,'\.'))"/>
  70. <xsl:value-of select="tokenize($xlink:href,'\.')[$tokens]"/>
  71. </xsl:function>
  72. <xsl:function name="wfs:namespace">
  73. <xsl:param name="xlink:href"/>
  74. <xsl:value-of select=" substring-before($xlink:href,'#')"/>
  75. </xsl:function>
  76. <xsl:function name="wfs:element">
  77. <xsl:param name="xlink:href"/>
  78. <xsl:variable name="element_w_fid" select="substring-after($xlink:href,'#')"/>
  79. <xsl:value-of select="substring-before($element_w_fid,'.')"/>
  80. </xsl:function>
  81. <xsl:function name="wfs:fid">
  82. <xsl:param name="xlink:href"/>
  83. <xsl:value-of select="concat( wfs:element($xlink:href),'.', wfs:primary_key($xlink:href))"/>
  84. </xsl:function>
  85. <xsl:template match="wfs:FeatureCollection" mode="grapht:analyze_nodes">
  86. <grapht:analyze_nodes>
  87. <xsl:for-each-group select=".//*[(*|@xlink:href) ]" group-by="name()">
  88. <xsl:copy copy-namespaces="no">
  89. <xsl:attribute name="grapht:count" select="count(current-group())"/>
  90. <xsl:attribute name="grapht:count.xlink" select="count(current-group()[@xlink:href])"/>
  91. <grapht:analyze_fid>
  92. <xsl:for-each-group select="current-group()[ matches(@p5:primaryKey,$debug.filter) ]" group-by="@fid">
  93. <xsl:for-each select="current-group()">
  94. <grapht:analyze_nodes.tree>
  95. <xsl:attribute name="fid" select="@fid"/>
  96. <!--<xsl:copy copy-namespaces="no">-->
  97. <!--<xsl:attribute name="fid" select="@fid"/>-->
  98. <grapht:analyze_nodes.tree.ancestors>
  99. <xsl:attribute name="grapht:parent.ancestor.count" select="count(ancestor::*)"/>
  100. <xsl:apply-templates mode="grapht:analyze_nodes.tree.ancestors" select="ancestor::*[*|@xlink:href]">
  101. <xsl:with-param name="grapht:parent.ancestor.count" select="count(ancestor::*)"/>
  102. </xsl:apply-templates>
  103. </grapht:analyze_nodes.tree.ancestors>
  104. <grapht:analyze_nodes.xlink.rebuild_tree_inputs>
  105. <xsl:for-each select=" current-group()[@xlink:href and matches(@p5:primaryKey,$debug.filter) ]" > <!-- -group group-by="@fid" -->
  106. <xsl:sort select="count(ancestor::node())"/>
  107. <xsl:copy copy-namespaces="no">
  108. <xsl:copy-of select="@*"/>
  109. <xsl:variable name="grapht.fid" select="wfs:fid(@xlink:href)"/>
  110. <xsl:attribute name="grapht.fid" select="$grapht.fid"/>
  111. <xsl:attribute name="grapht:ancestor.count" select="count(ancestor::node())"/>
  112. <xsl:apply-templates mode="grapht:analyze_nodes.xlink.rebuild_tree" select="root()//*[*[@fid= $grapht.fid ]]"> <!-- and * -->
  113. <xsl:with-param name="fid" select="$grapht.fid"/>
  114. <xsl:with-param name="root.node" select="root()"/>
  115. </xsl:apply-templates>
  116. </xsl:copy>
  117. </xsl:for-each>
  118. </grapht:analyze_nodes.xlink.rebuild_tree_inputs>
  119. <!--</xsl:copy>-->
  120. </grapht:analyze_nodes.tree>
  121. </xsl:for-each>
  122. </xsl:for-each-group>
  123. </grapht:analyze_fid>
  124. </xsl:copy>
  125. </xsl:for-each-group>
  126. </grapht:analyze_nodes>
  127. </xsl:template>
  128. <xsl:template match="*" mode="grapht:analyze_nodes.tree.ancestors">
  129. <xsl:param name="grapht:parent.ancestor.count" required="yes"/>
  130. <xsl:copy copy-namespaces="no">
  131. <xsl:copy-of select="@*"/>
  132. <xsl:attribute name="grapht:ancestor.count" select="count(ancestor::*)"/>
  133. <xsl:attribute name="grapht:ancestor.path.len" select="$grapht:parent.ancestor.count - count(ancestor::*)"/>
  134. </xsl:copy>
  135. </xsl:template>
  136. <xsl:template match="*[not(@fid or @xlink:href)]" mode="grapht:analyze_nodes.tree.ancestors"/>
  137. <xsl:template match="*" mode="grapht:analyze_nodes.xlink.rebuild_tree">
  138. <xsl:param name="fid" required="yes"/>
  139. <xsl:param name="root.node" required="yes"/>
  140. <xsl:copy copy-namespaces="no">
  141. <!--<xsl:element name="{../name()}">-->
  142. <xsl:copy-of select="@*"/>
  143. <!--</xsl:element>-->
  144. </xsl:copy>
  145. </xsl:template>
  146. <xsl:template match="grapht:analyze_nodes" mode="grapht:analyze_nodes.paths">
  147. <grapht:analyze_nodes.paths>
  148. <xsl:apply-templates mode="grapht:analyze_nodes.paths"/>
  149. </grapht:analyze_nodes.paths>
  150. </xsl:template>
  151. <xsl:template match="*" mode="grapht:analyze_nodes.paths">
  152. <xsl:copy copy-namespaces="no">
  153. <xsl:copy-of select="@*"/>
  154. <xsl:apply-templates mode="grapht:analyze_nodes.paths"/>
  155. </xsl:copy>
  156. </xsl:template>
  157. <xsl:template match="grapht:analyze_fid" mode="grapht:analyze_nodes.paths">
  158. <!-- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  159. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  160. -->
  161. <xsl:copy copy-namespaces="no">
  162. <xsl:copy-of select="@*"/>
  163. <xsl:for-each-group select="grapht:analyze_nodes.tree" group-by="@fid">
  164. <xsl:variable name="current.parent.fid" select="@fid"/>
  165. <xsl:copy copy-namespaces="no">
  166. <xsl:copy-of select="@*"/>
  167. <grapht:analyze_nodes.tree.ancestors>
  168. <xsl:for-each-group select="current-group()/grapht:analyze_nodes.tree.ancestors/*" group-by="@fid">
  169. <xsl:sort select="@fid"/><!-- grapht:ancestor.path.len -->
  170. <xsl:copy copy-namespaces="no">
  171. <xsl:copy-of select="@*"/>
  172. <grapht:analyze_nodes.tree.ancestors.paths.to_childs>
  173. <xsl:for-each select="current-group()">
  174. <xsl:copy copy-namespaces="no">
  175. <xsl:copy-of select="@*"/>
  176. <grapht:analyze_nodes.tree.ancestors.paths.to_childs.childs>
  177. <xsl:attribute name="debug">#223 dla znalezionych ojcow, szukam innych dzieci </xsl:attribute>
  178. <xsl:for-each select="root()//grapht:analyze_fid/grapht:analyze_nodes.tree[not(@fid=$current.parent.fid)]/grapht:analyze_nodes.tree.ancestors/*[@fid= current()/@fid]">
  179. <xsl:copy copy-namespaces="no">
  180. <xsl:copy-of select="@*"/>
  181. <!--<xsl:for-each select="ancestor::*">
  182. <ancestor>
  183. <xsl:copy copy-namespaces="no">
  184. <xsl:copy-of select="@*"/>
  185. </xsl:copy>
  186. </ancestor>
  187. </xsl:for-each>-->
  188. </xsl:copy>
  189. </xsl:for-each>
  190. </grapht:analyze_nodes.tree.ancestors.paths.to_childs.childs>
  191. </xsl:copy>
  192. </xsl:for-each>
  193. </grapht:analyze_nodes.tree.ancestors.paths.to_childs>
  194. </xsl:copy>
  195. </xsl:for-each-group>
  196. </grapht:analyze_nodes.tree.ancestors>
  197. </xsl:copy>
  198. </xsl:for-each-group>
  199. </xsl:copy>
  200. </xsl:template>
  201. <!--<xsl:template match="*" mode="grapht:analyze_nodes.paths.analyze_fid">
  202. <xsl:copy copy-namespaces="no">
  203. <xsl:copy-of select="@*"/>
  204. <!-\- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  205. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  206. -\->
  207. <xsl:for-each-group select=""></xsl:for-each-group>
  208. </xsl:copy>
  209. </xsl:template>-->
  210. </xsl:stylesheet>