grapht.xsl 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. xmlns:default_db__x3A__BI_audit_ENERGA_PRACOWNICY_adresy="https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_PRACOWNICY_adresy"
  26. xmlns:xp5r="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache.public/xinclude_p5_recurse/xinclude_p5_recurse.xsd"
  27. version="2.0">
  28. <xsl:output indent="yes"/>
  29. <xsl:strip-space elements="*"/>
  30. <xsl:template match="get_wfs_recurse_xsl:context.PRIMARYKEY|get_wfs_recurse_xsl:nodes" mode="#all"/>
  31. <xsl:param name="grapht.temp"/>
  32. <xsl:param name="debug.filter" select="'(9177)|(9177)'"/>
  33. <xsl:param name="grapht.xsl.testing"/>
  34. <xsl:param name="grapht.testing.analyze_nodes.grapht.fid.xml"/>
  35. <xsl:key name="fid" match="*" use="@grapht:fid"/>
  36. <xsl:key name="descendant-or-self" match="*" use="descendant-or-self::*/@grapht:fid"/>
  37. <xsl:key name="descendant" match="*" use="descendant::*/@grapht:fid"/>
  38. <!--<xsl:key name="descendant" match="descendant::" use="@grapht:fid"/>-->
  39. <xsl:key name="ancestor" match="*" use="ancestor::*/@grapht:fid"/>
  40. <!--<xsl:key name="ancestor" match="ancestor::*" use="@grapht:fid"/>-->
  41. <!--
  42. założenia:
  43. - graf ma max głębokość $maxDeepth -
  44. - 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.
  45. - wyzwolenie liczenia powiązań do wszystkich ścieżek wyzwalamy od jakiegos poziomu do szczytu $currentStartDeepth,
  46. tyle razy dokladamy rekursywnie @xlink, aby osiągnąć $maxDeepth ($toTraverseDeept = $maxDeepth - $currentStartDeepth)
  47. - todo kierunkowe relacje na razie ignorujemy (@backReffed), do rozwazenia implementacji w obliczeniach aby nie liczyc sciezek,
  48. dotyczących relacji przebiegajacych przez backreffy - pytanie w jakich jest to zaleznosciach - do przeanalizowania
  49. - szukamy zawsze listy elementow, dla każdego elementu:
  50. - w górę
  51. - w dół
  52. - @grapht:ancestor.path.len = dlugosc pomiedzy parentem i dzieckiem = $grapht:parent.ancestor.count - $grapht:ancestor.count w elemencie grapht:analyze_nodes.tree.ancestors
  53. - drugie przetworzenie umożliwi znalezienie tras pomiedzy elementami suma z gory + kawalek do gory - bierzemy ktory krótszy
  54. Plan B
  55. - jaka odleglosc od FID do FID i najkrotsza sciezka?
  56. 1 szukam samych koncow dzieci z xlink,
  57. 2 dla kazdego z nich jade sciezki do root - moga byc wiele razy
  58. 3 dla kazdego z nich sciezki do child (sa do zsumowania) - sa na koncach - bez sensu
  59. C
  60. mamy unikalne sciezki w grapht:last_child.fid
  61. kazdy wezel ma przypisana grapht:last_child.fid - mozna zgrupowac - i po tych wariantach szukac
  62. dla kazdego wezla group by grapht:last_child.fid szukam dlugosci do innego :
  63. - szukam w jakich sciezkach jest tamten wezel i uzywam @grapht:ancestor.path.len
  64. foreach grapht:analyze_nodes.tree group by ../@grapht:last_child.fid
  65. szukam grapht:analyze_nodes.tree[ have grapht:analyze_nodes.tree.childs ]
  66. deb[5] BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448 to
  67. [4] BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619447
  68. tracking manually:
  69. BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448 - source
  70. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row.241314
  71. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619449
  72. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row.241314
  73. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448
  74. ../BI_audit_ENERGA_PRACOWNICY.9 (root)
  75. ./BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619441
  76. ./BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row.241313
  77. ./BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619447 - cel
  78. dlugosc = 9
  79. <grapht:analyze_nodes.tree fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448"
  80. p5:primaryKey="1619448"
  81. xlink:href=""
  82. grapht:pos="1"
  83. grapht:anchestor.count="3"
  84. grapht:childs.count="202"
  85. grapht:last_child.fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448"
  86. grapht:fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619448">
  87. <grapht:analyze_nodes.tree.childs grapht:parent.childs.count="202" grapht:parent.ancestor.count="3"/>
  88. </grapht:analyze_nodes.tree>
  89. <grapht:analyze_nodes.tree fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619447"
  90. p5:primaryKey="1619447"
  91. xlink:href=""
  92. grapht:pos="21"
  93. grapht:anchestor.count="5"
  94. grapht:childs.count="87"
  95. grapht:last_child.fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619441"
  96. grapht:fid="BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619447">
  97. <grapht:analyze_nodes.tree.childs grapht:parent.childs.count="87" grapht:parent.ancestor.count="5"/>
  98. </grapht:analyze_nodes.tree>
  99. - inne last_child.fid
  100. - sprawdzmy cos co sie dzieli w srodku
  101. np: BI_audit_KRS_person.150746 [4]
  102. do BI_audit_ENERGA_RUM_KONTRAHENCI.9177 [7]
  103. sciezka:
  104. BI_audit_ENERGA_RUM_KONTRAHENCI.9177
  105. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619451
  106. ../BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row.241314 (local root)
  107. ./BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1619449
  108. ./BI_audit_KRS_person.150746
  109. plan D
  110. dla kazdego kto nie ma sciezek,
  111. wychodzmy pietro wyzej i patrzymy, czy widzimy dziecko,
  112. jak nie wyzej
  113. -->
  114. <!--
  115. a.binder Metody optumalizacji wizualizacji danych do weryfikacji czy są gotowe funckje/biblioteki do tego
  116. 1) NearestMiddleShortcut
  117. A - B - C => A - - - C
  118. 2) MiddlePathShortcut
  119. A - B - C - D => A - - - D
  120. 3) MiddleGroup
  121. - C1 - D1 / - D1
  122. A - B + => A [B: C1,C2 ] -
  123. - C2 - D2 \ - D2
  124. 4) CutPath
  125. A - B - C - D => C - D
  126. 5) TypesGroup
  127. A1 - B1 - C1
  128. A2 - B2 - C2 => [ A1, A2, A3 ] = [ B1, B2, B3 ] = [ C1, C2, C3 ]
  129. A3 - B3 - C3
  130. 6) TypesAndFlowsGroup
  131. [ ] - - - - - - [ ]
  132. A1 - B1 - C1 [ A1 ] [ B1 ]- - [ C1 ]
  133. C2 - B2 - A2 => [ B2 ]- - [ A2 ] [ C3 ]
  134. B3 - A3 - C3 [ B3 ] [ A3 ]
  135. mixing this types also
  136. -->
  137. <xsl:function name="wfs:primary_key">
  138. <xsl:param name="xlink:href"/>
  139. <xsl:variable name="tokens" select="count(tokenize($xlink:href,'\.'))"/>
  140. <xsl:value-of select="tokenize($xlink:href,'\.')[$tokens]"/>
  141. </xsl:function>
  142. <xsl:function name="wfs:namespace">
  143. <xsl:param name="xlink:href"/>
  144. <xsl:value-of select=" substring-before($xlink:href,'#')"/>
  145. </xsl:function>
  146. <xsl:function name="wfs:element">
  147. <xsl:param name="xlink:href"/>
  148. <xsl:variable name="element_w_fid" select="substring-after($xlink:href,'#')"/>
  149. <xsl:value-of select="substring-before($element_w_fid,'.')"/>
  150. </xsl:function>
  151. <xsl:function name="wfs:fid">
  152. <xsl:param name="xlink:href"/>
  153. <xsl:if test="string-length($xlink:href) &gt;0">
  154. <xsl:value-of select="concat( wfs:element($xlink:href),'.', wfs:primary_key($xlink:href))"/>
  155. </xsl:if>
  156. </xsl:function>
  157. <xsl:template match="@fid" mode="grapht:fid">
  158. <xsl:attribute name="grapht:fid" select="."/>
  159. </xsl:template>
  160. <xsl:template match="@xlink:href" mode="grapht:fid">
  161. <xsl:attribute name="grapht:fid" select="wfs:fid(.)"/>
  162. </xsl:template>
  163. <xsl:template match="@*" mode="grapht:fid"/>
  164. <xsl:template match="wfs:FeatureCollection" mode="grapht:analyze_nodes">
  165. <grapht:analyze_nodes>
  166. <xsl:for-each-group select=".//*[(*|@xlink:href) and not(name()='gml:featureMember')]" group-by="name()">
  167. <xsl:copy copy-namespaces="no">
  168. <xsl:attribute name="grapht:count" select="count(current-group())"/>
  169. <xsl:attribute name="grapht:count.xlink" select="count(current-group()[@xlink:href])"/>
  170. <xp5r:cache xmlns:xp5r="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache.public/xinclude_p5_recurse/xinclude_p5_recurse.xsd"
  171. xp5r:id="{local-name()}"
  172. xp5r:basedir="{$grapht.temp}"
  173. xp5r:stylesheet="{$grapht.xsl.testing}">
  174. <xp5r:namespace namespace="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/graph_tree/graph_tree.xsd" name="grapht"/>
  175. <xp5r:namespace namespace="http://www.opengis.net/wfs" name="wfs"/>
  176. <xp5r:namespace namespace="http://www.opengis.net/gml" name="gml"/>
  177. <xp5r:namespace namespace="http://www.w3.org/1999/xlink" name="xlink"/>
  178. <xp5r:param name="debug.filter" value="{$debug.filter}"/>
  179. <xp5r:apply-template mode="grapht:analyze_nodes.xp5r" select=".">
  180. <xp5r:context-node>
  181. <xp5r:for-each-group
  182. select="doc('{$grapht.testing.analyze_nodes.grapht.fid.xml}')/wfs:FeatureCollection//*[(*|@xlink:href) and not(name()='gml:featureMember') and name()='{name()}']"
  183. group-by="name()"/>
  184. </xp5r:context-node>
  185. <!--<xsl:apply-templates mode="grapht:analyze_nodes.xp5r" select="."/>-->
  186. </xp5r:apply-template>
  187. </xp5r:cache>
  188. </xsl:copy>
  189. </xsl:for-each-group>
  190. </grapht:analyze_nodes>
  191. </xsl:template>
  192. <xsl:template match="*" mode="grapht:analyze_nodes.xp5r">
  193. <grapht:analyze_fid><!-- for name grouped -->
  194. <!--<debug.copy>
  195. <xsl:copy>
  196. <xsl:copy-of select="@*"/>
  197. <current.group>
  198. <xsl:copy-of select="current-group()"/>
  199. </current.group>
  200. <current.root>
  201. <xsl:copy-of select="root()"/>
  202. </current.root>
  203. </xsl:copy>
  204. </debug.copy>-->
  205. <!--<xsl:for-each-group select="current-group()[ matches(@p5:primaryKey,$debug.filter) ]" group-by="@fid">-->
  206. <xsl:for-each select="current-group()[ count(descendant::*[* |@xlink:href]) &gt;0 and matches(@p5:primaryKey,$debug.filter) ]"> <!-- FILTER -->
  207. <xsl:message>#136 maching @fid=<xsl:value-of select="@fid"/>; for matches(@p5:primaryKey=<xsl:value-of select="@p5:primaryKey"/>,$debug.filter=<xsl:value-of select="$debug.filter"/>) </xsl:message>
  208. <grapht:analyze_nodes.tree>
  209. <xsl:attribute name="fid" select="@fid"/>
  210. <xsl:attribute name="p5:primaryKey" select="@p5:primaryKey"/>
  211. <xsl:attribute name="xlink:href" select="@xlink:href"/>
  212. <xsl:attribute name="grapht:pos" select="position()"/>
  213. <xsl:variable name="grapht:anchestor.count" select=" count(ancestor::*)"/>
  214. <xsl:attribute name="grapht:anchestor.count" select="$grapht:anchestor.count"/>
  215. <xsl:variable name="grapht:childs.count" select="count(descendant::*[* |@xlink:href])"/>
  216. <xsl:attribute name="grapht:childs.count" select="$grapht:childs.count"/>
  217. <xsl:variable name="grapht:last_child.fid" select="descendant::*[ * | @xlink:href][$grapht:childs.count]/concat(@fid,wfs:fid(@xlink:href))"/>
  218. <xsl:attribute name="grapht:last_child.fid" select="$grapht:last_child.fid"/>
  219. <!--<xsl:attribute name="grapht:root.fid" select=" ancestor::*[@fid][1]/@fid"/>-->
  220. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  221. <!--<xsl:copy copy-namespaces="no">-->
  222. <!--<xsl:attribute name="fid" select="@fid"/>-->
  223. <!--<grapht:analyze_nodes.tree.childs>
  224. <xsl:attribute name="grapht:parent.childs.count" select="$grapht:childs.count"/>
  225. <xsl:attribute name="grapht:parent.ancestor.count" select="count( ancestor::*)"/>
  226. <!-\-<xsl:apply-templates mode="grapht:analyze_nodes.tree.childs" select="descendant::*[*|@xlink:href]">
  227. <xsl:with-param name="grapht:parent.childs.count" select="$grapht:childs.count"/>
  228. <xsl:with-param name="grapht:parent.ancestor.count" select="count(ancestor::*)"/>
  229. <xsl:with-param name="grapht:last_child.fid" select="$grapht:last_child.fid"/>
  230. </xsl:apply-templates>-\->
  231. <!-\-<xsl:for-each-group select="descendant::*[*|@xlink:href]" group-by="concat(@fid,wfs:fid(@xlink:href))">
  232. <xsl:apply-templates mode="grapht:analyze_nodes.tree.childs" select=".">
  233. <xsl:with-param name="grapht:parent.childs.count" select="$grapht:childs.count"/>
  234. <xsl:with-param name="grapht:parent.ancestor.count" select="count(ancestor::*)"/>
  235. <xsl:with-param name="grapht:last_child.fid" select="$grapht:last_child.fid"/>
  236. </xsl:apply-templates>
  237. </xsl:for-each-group>-\->
  238. </grapht:analyze_nodes.tree.childs>-->
  239. <!--<grapht:analyze_nodes.xlink.rebuild_tree_inputs>
  240. <xsl:attribute name="debug">#147 temporary disabled</xsl:attribute>
  241. <!-\-<xsl:for-each select=" current-group()[@xlink:href and matches(@p5:primaryKey,$debug.filter) ]" > <!-\\- -group group-by="@fid" -\\->
  242. <xsl:sort select="count(ancestor::node())"/>
  243. <xsl:copy copy-namespaces="no">
  244. <xsl:copy-of select="@*"/>
  245. <xsl:variable name="grapht.fid" select="wfs:fid(@xlink:href)"/>
  246. <xsl:attribute name="grapht.fid" select="$grapht.fid"/>
  247. <xsl:attribute name="grapht:ancestor.count" select="count(ancestor::node())"/>
  248. <xsl:apply-templates mode="grapht:analyze_nodes.xlink.rebuild_tree" select="root()//*[*[@fid= $grapht.fid ]]"> <!-\\- and * -\\->
  249. <xsl:with-param name="fid" select="$grapht.fid"/>
  250. <xsl:with-param name="root.node" select="root()"/>
  251. </xsl:apply-templates>
  252. </xsl:copy>
  253. </xsl:for-each>-\->
  254. </grapht:analyze_nodes.xlink.rebuild_tree_inputs>-->
  255. <!--</xsl:copy>-->
  256. <grapht:analyze_nodes.tree.clousure.searched>
  257. <xsl:variable name="current.parent.fid" select="@grapht:fid"/>
  258. <xsl:for-each select="root()//*[ not(@grapht:fid = $current.parent.fid) and (* or @xlink:href or @fid) and ( matches(@p5:primaryKey,$debug.filter) )]"> <!-- or matches($current.parent.fid,$debug.filter) FILTER -->
  259. <!--<xsl:message>#280 searching path from <xsl:value-of select="$current.parent.fid"/> to <xsl:value-of select="concat(@fid,wfs:fid(@xlink:href))"/></xsl:message>-->
  260. <grapht:path_to>
  261. <xsl:attribute name="grapht:fid" select="@grapht:fid"/>
  262. <xsl:choose>
  263. <xsl:when test="ancestor::*[@grapht:fid=$current.parent.fid ]"><!--<xsl:when test="ancestor::*[@grapht:fid=$current.parent.fid ]">--> <!-- key('ancestor',$current.parent.fid) -->
  264. <!--<xsl:message>#285 parent path found for <xsl:value-of select="$current.parent.fid"/> </xsl:message>-->
  265. <xsl:variable name="curr.ancerstor.count" select="count(ancestor::*)"/> <!-- -->
  266. <xsl:variable name="parent.ancerstor.count" select="ancestor::*[@grapht:fid=$current.parent.fid][1]/count(ancestor::*)"/> <!-- select="ancestor::*[@grapht:fid=$current.parent.fid][1]/count(ancestor::*)" --> <!-- key('ancestor',$current.parent.fid)[1]/count(ancestor::*) -->
  267. <xsl:variable name="grapht:path" select="$curr.ancerstor.count - $parent.ancerstor.count"/>
  268. <grapht:path_info>
  269. <xsl:attribute name="curr.ancerstor.count" select="$curr.ancerstor.count"/>
  270. <xsl:attribute name="parent.ancerstor.count" select="$parent.ancerstor.count"/>
  271. <xsl:attribute name="grapht:path" select="$grapht:path"/>
  272. <xsl:attribute name="grapht:node_from" select="@grapht:fid"/>
  273. <xsl:attribute name="grapht:when" select="'ancestor'"/>
  274. </grapht:path_info>
  275. <grapht:path_step>
  276. <!--<xsl:copy-of select="@grapht:fid"/>-->
  277. <xsl:copy-of select="@p5:primaryKey"/>
  278. <xsl:attribute name="local-name" select="local-name()"/>
  279. </grapht:path_step>
  280. <xsl:for-each select="ancestor::* [ count(ancestor::*) &gt;= $parent.ancerstor.count]"> <!-- ancestor::* [ count(ancestor::*) &gt;= $parent.ancerstor.count] -->
  281. <!-- <xsl:if test=" count(ancestor::*) &gt; $parent.ancerstor.count ">-->
  282. <grapht:path_step>
  283. <!--<xsl:copy-of select="@grapht:fid"/>-->
  284. <xsl:copy-of select="@p5:primaryKey"/>
  285. <xsl:attribute name="local-name" select="local-name()"/>
  286. <!--<xsl:attribute name="debug.anc.count" select="count(ancestor::*)"/>-->
  287. </grapht:path_step>
  288. <!--</xsl:if>-->
  289. </xsl:for-each>
  290. </xsl:when>
  291. <xsl:otherwise>
  292. <xsl:apply-templates mode="grapht:analyze_nodes.tree.clousure.searched" select="." >
  293. <xsl:with-param name="current.parent.fid" select="$current.parent.fid"/>
  294. <xsl:with-param name="grapht:fid" select="@grapht:fid"/>
  295. </xsl:apply-templates>
  296. </xsl:otherwise>
  297. </xsl:choose>
  298. </grapht:path_to>
  299. </xsl:for-each>
  300. </grapht:analyze_nodes.tree.clousure.searched>
  301. </grapht:analyze_nodes.tree>
  302. </xsl:for-each>
  303. <!--</xsl:for-each-group>-->
  304. </grapht:analyze_fid>
  305. </xsl:template>
  306. <xsl:template match="*" mode="grapht:analyze_nodes.tree.childs">
  307. <xsl:param name="grapht:parent.childs.count" required="yes"/>
  308. <xsl:param name="grapht:parent.ancestor.count" required="yes"/>
  309. <xsl:param name="grapht:last_child.fid" required="yes"/>
  310. <xsl:variable name="grapht:childs.count" select="count(descendant::*[* |@xlink:href])"/>
  311. <xsl:copy copy-namespaces="no">
  312. <xsl:copy-of select="@*"/>
  313. <xsl:attribute name="grapht:last_child.fid" select="descendant::*[ * | @xlink:href][$grapht:childs.count]/concat(@fid,wfs:fid(@xlink:href))"/>
  314. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  315. <xsl:attribute name="grapht:ancestor.count" select="count(ancestor::*)"/>
  316. <xsl:attribute name="grapht:childs.count" select="$grapht:childs.count"/>
  317. <xsl:attribute name="grapht:parent.ancestor.count" select="$grapht:parent.ancestor.count"/>
  318. <xsl:attribute name="grapht:ancestor.path.len" select="count(ancestor::*) - $grapht:parent.ancestor.count"/>
  319. <xsl:attribute name="grapht:last_child.fid" select="$grapht:last_child.fid"/>
  320. </xsl:copy>
  321. </xsl:template>
  322. <xsl:template match="*[not(@fid or @xlink:href)]" mode="grapht:analyze_nodes.tree.childs"/>
  323. <xsl:template match="*" mode="grapht:analyze_nodes.xlink.rebuild_tree">
  324. <xsl:param name="fid" required="yes"/>
  325. <xsl:param name="root.node" required="yes"/>
  326. <xsl:copy copy-namespaces="no">
  327. <!--<xsl:element name="{../name()}">-->
  328. <xsl:copy-of select="@*"/>
  329. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  330. <!--</xsl:element>-->
  331. </xsl:copy>
  332. </xsl:template>
  333. <!-- todo unique grapht:analyze_nodes.tree.ancestors -->
  334. <xsl:template match="grapht:analyze_nodes" mode="grapht:analyze_nodes.paths">
  335. <grapht:analyze_nodes.paths>
  336. <xsl:apply-templates mode="grapht:analyze_nodes.paths"/>
  337. </grapht:analyze_nodes.paths>
  338. </xsl:template>
  339. <xsl:template match="*" mode="grapht:analyze_nodes.paths">
  340. <xsl:copy copy-namespaces="no">
  341. <xsl:copy-of select="@*"/>
  342. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  343. <xsl:apply-templates mode="grapht:analyze_nodes.paths"/>
  344. </xsl:copy>
  345. </xsl:template>
  346. <xsl:template match="gml:featureMember" mode="grapht:analyze_nodes.paths grapht:analyze_nodes.paths.unique"/>
  347. <xsl:template match="grapht:analyze_fid" mode="grapht:analyze_nodes.paths">
  348. <!-- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  349. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  350. -->
  351. <xsl:message>#217 running grapht:analyze_nodes.paths with debug.filter=<xsl:value-of select="$debug.filter"/></xsl:message>
  352. <xsl:copy copy-namespaces="no">
  353. <xsl:copy-of select="@*"/>
  354. <xsl:for-each select="grapht:analyze_nodes.tree" > <!-- group-by="@fid" -->
  355. <xsl:message>#221 foreach grapht:analyze_nodes.tree @grapht:fid=<xsl:value-of select="@grapht:fid"/>; @grapht:pos=<xsl:value-of select="@grapht:pos"/>; group-by="@fid"=<xsl:value-of select="@fid"/>; @p5:primaryKey=<xsl:value-of select="@p5:primaryKey"/>; </xsl:message>
  356. <xsl:variable name="current.parent.fid" select="@grapht:fid"/>
  357. <xsl:variable name="current.parent.pos" select="@grapht:pos"/>
  358. <xsl:variable name="grapht:last_child.fid" select="@grapht:last_child.fid"/>
  359. <xsl:variable name="grapht:anchestor.count" select="@grapht:anchestor.count"/>
  360. <xsl:copy copy-namespaces="no">
  361. <xsl:copy-of select="@*"/>
  362. <grapht:analyze_nodes.tree.clousure>
  363. <!--<xsl:attribute name="debug.288"> looking for @grapht:last_child.fid=$grapht:last_child.fid = <xsl:value-of select="$grapht:last_child.fid"/> ] </xsl:attribute>-->
  364. <xsl:for-each select="root()//grapht:analyze_nodes.tree[not(@grapht:fid = $current.parent.fid) and @grapht:last_child.fid=$grapht:last_child.fid and ( matches(@p5:primaryKey,$debug.filter) or matches($current.parent.fid,$debug.filter) ) ]"> <!-- FILTER -->
  365. <grapht:path>
  366. <xsl:attribute name="grapht:path.len" select="$grapht:anchestor.count - number(@grapht:anchestor.count) "/>
  367. <xsl:attribute name="grapht:fid" select="@grapht:fid"/>
  368. <xsl:copy-of select="@*"/>
  369. </grapht:path>
  370. </xsl:for-each>
  371. </grapht:analyze_nodes.tree.clousure>
  372. </xsl:copy>
  373. </xsl:for-each>
  374. </xsl:copy>
  375. </xsl:template>
  376. <!--<xsl:template match="grapht:analyze_fid" mode="grapht:analyze_nodes.paths">
  377. <!-\- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  378. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  379. -\->
  380. <xsl:message>#217 running grapht:analyze_nodes.paths with debug.filter=<xsl:value-of select="$debug.filter"/></xsl:message>
  381. <xsl:copy copy-namespaces="no">
  382. <xsl:copy-of select="@*"/>
  383. <xsl:for-each select="grapht:analyze_nodes.tree" > <!-\- group-by="@fid" -\->
  384. <xsl:message>#221 foreach grapht:analyze_nodes.tree @grapht:fid=<xsl:value-of select="@grapht:fid"/>; @grapht:pos=<xsl:value-of select="@grapht:pos"/>; group-by="@fid"=<xsl:value-of select="@fid"/>; @p5:primaryKey=<xsl:value-of select="@p5:primaryKey"/>; </xsl:message>
  385. <xsl:variable name="current.parent.fid" select="@grapht:fid"/>
  386. <xsl:variable name="current.parent.pos" select="@grapht:pos"/>
  387. <xsl:copy copy-namespaces="no">
  388. <xsl:copy-of select="@*"/>
  389. <grapht:analyze_nodes.tree.ancestors>
  390. <xsl:for-each select="grapht:analyze_nodes.tree.childs/*[ matches(@p5:primaryKey,$debug.filter) ]" ><!-\-group-by="@fid" FILTERING -\->
  391. <xsl:sort select="@grapht:fid"/>
  392. <xsl:variable name="current.analyze_nodes.tree.ancestors.fid" select="@grapht:fid"/>
  393. <!-\-<xsl:variable name="current.analyze_nodes.tree.ancestors.pos" select="@grapht:pos"/>-\->
  394. <xsl:message>#245 current.analyze_nodes.tree.ancestors.fid=<xsl:value-of select="@grapht:fid"/>; <!-\-@grapht:pos=<xsl:value-of select="@grapht:pos"/>;-\-></xsl:message>
  395. <!-\- grapht:ancestor.path.len -\->
  396. <xsl:copy copy-namespaces="no">
  397. <xsl:copy-of select="@*"/>
  398. <grapht:analyze_nodes.tree.childs.paths.to_childs>
  399. <!-\- <xsl:for-each select="current-group()">
  400. <xsl:copy copy-namespaces="no">
  401. <xsl:copy-of select="@*"/>-\->
  402. <grapht:analyze_nodes.tree.childs.paths.to_childs.childs>
  403. <xsl:attribute name="debug">#223 dla znalezionych ojcow, szukam innych dzieci </xsl:attribute>
  404. <xsl:for-each select="root()//grapht:analyze_fid/grapht:analyze_nodes.tree[not(@grapht:fid=$current.parent.fid)]/grapht:analyze_nodes.tree.childs/*[@grapht:fid = $current.analyze_nodes.tree.ancestors.fid and matches(@p5:primaryKey,$debug.filter)]"> <!-\- FILTER -\->
  405. <xsl:copy copy-namespaces="no">
  406. <xsl:copy-of select="@*"/>
  407. <!-\-<xsl:for-each select="ancestor::*">
  408. <ancestor>
  409. <xsl:copy copy-namespaces="no">
  410. <xsl:copy-of select="@*"/>
  411. </xsl:copy>
  412. </ancestor>
  413. </xsl:for-each>-\->
  414. </xsl:copy>
  415. </xsl:for-each>
  416. </grapht:analyze_nodes.tree.childs.paths.to_childs.childs>
  417. <!-\-</xsl:copy>
  418. </xsl:for-each>-\->
  419. </grapht:analyze_nodes.tree.childs.paths.to_childs>
  420. </xsl:copy>
  421. </xsl:for-each>
  422. </grapht:analyze_nodes.tree.ancestors>
  423. </xsl:copy>
  424. </xsl:for-each>
  425. </xsl:copy>
  426. </xsl:template>-->
  427. <!--<xsl:template match="grapht:analyze_fid" mode="grapht:analyze_nodes.paths">
  428. <!-\- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  429. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  430. -\->
  431. <xsl:message>#217 running grapht:analyze_nodes.paths with debug.filter=<xsl:value-of select="$debug.filter"/></xsl:message>
  432. <xsl:copy copy-namespaces="no">
  433. <xsl:copy-of select="@*"/>
  434. <xsl:for-each select="grapht:analyze_nodes.tree" > <!-\- group-by="@fid" -\->
  435. <xsl:message>#221 foreach grapht:analyze_nodes.tree @grapht:fid=<xsl:value-of select="@grapht:fid"/>; @grapht:pos=<xsl:value-of select="@grapht:pos"/>; group-by="@fid"=<xsl:value-of select="@fid"/>; @p5:primaryKey=<xsl:value-of select="@p5:primaryKey"/>; </xsl:message>
  436. <xsl:variable name="current.parent.fid" select="@grapht:fid"/>
  437. <xsl:variable name="current.parent.pos" select="@grapht:pos"/>
  438. <xsl:copy copy-namespaces="no">
  439. <xsl:copy-of select="@*"/>
  440. <grapht:analyze_nodes.tree.ancestors>
  441. <xsl:for-each select="grapht:analyze_nodes.tree.childs/*[ matches(@p5:primaryKey,$debug.filter) ]" ><!-\-group-by="@fid" FILTERING -\->
  442. <xsl:sort select="@grapht:fid"/>
  443. <xsl:variable name="current.analyze_nodes.tree.ancestors.fid" select="@grapht:fid"/>
  444. <!-\-<xsl:variable name="current.analyze_nodes.tree.ancestors.pos" select="@grapht:pos"/>-\->
  445. <xsl:message>#245 current.analyze_nodes.tree.ancestors.fid=<xsl:value-of select="@grapht:fid"/>; <!-\-@grapht:pos=<xsl:value-of select="@grapht:pos"/>;-\-></xsl:message>
  446. <!-\- grapht:ancestor.path.len -\->
  447. <xsl:copy copy-namespaces="no">
  448. <xsl:copy-of select="@*"/>
  449. <grapht:analyze_nodes.tree.childs.paths.to_childs>
  450. <!-\- <xsl:for-each select="current-group()">
  451. <xsl:copy copy-namespaces="no">
  452. <xsl:copy-of select="@*"/>-\->
  453. <grapht:analyze_nodes.tree.childs.paths.to_childs.childs>
  454. <xsl:attribute name="debug">#223 dla znalezionych ojcow, szukam innych dzieci </xsl:attribute>
  455. <xsl:for-each select="root()//grapht:analyze_fid/grapht:analyze_nodes.tree[not(@grapht:fid=$current.parent.fid)]/grapht:analyze_nodes.tree.childs/*[@grapht:fid = $current.analyze_nodes.tree.ancestors.fid and matches(@p5:primaryKey,$debug.filter)]"> <!-\- FILTER -\->
  456. <xsl:copy copy-namespaces="no">
  457. <xsl:copy-of select="@*"/>
  458. <!-\-<xsl:for-each select="ancestor::*">
  459. <ancestor>
  460. <xsl:copy copy-namespaces="no">
  461. <xsl:copy-of select="@*"/>
  462. </xsl:copy>
  463. </ancestor>
  464. </xsl:for-each>-\->
  465. </xsl:copy>
  466. </xsl:for-each>
  467. </grapht:analyze_nodes.tree.childs.paths.to_childs.childs>
  468. <!-\-</xsl:copy>
  469. </xsl:for-each>-\->
  470. </grapht:analyze_nodes.tree.childs.paths.to_childs>
  471. </xsl:copy>
  472. </xsl:for-each>
  473. </grapht:analyze_nodes.tree.ancestors>
  474. </xsl:copy>
  475. </xsl:for-each>
  476. </xsl:copy>
  477. </xsl:template>-->
  478. <!--<xsl:template match="*" mode="grapht:analyze_nodes.paths.analyze_fid">
  479. <xsl:copy copy-namespaces="no">
  480. <xsl:copy-of select="@*"/>
  481. <!-\- szukam unkalnych parentow jakie mam, z najkrotsza sciezka
  482. , a potem szukam dla nich jakie oni maja dzieci unikalne, najkrotsze sciezki
  483. -\->
  484. <xsl:for-each-group select=""></xsl:for-each-group>
  485. </xsl:copy>
  486. </xsl:template>-->
  487. <xsl:template match="*" mode="grapht:analyze_nodes.grapht.fid">
  488. <xsl:copy copy-namespaces="no">
  489. <xsl:copy-of select="@*"/>
  490. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  491. <xsl:apply-templates mode="#current"/>
  492. </xsl:copy>
  493. </xsl:template>
  494. <xsl:template match="grapht:analyze_nodes.paths" mode="grapht:analyze_nodes.paths.unique">
  495. <grapht:analyze_nodes.paths.unique>
  496. <xsl:apply-templates mode="#current"/>
  497. </grapht:analyze_nodes.paths.unique>
  498. </xsl:template>
  499. <xsl:template match="*" mode="grapht:analyze_nodes.paths.unique">
  500. <xsl:copy copy-namespaces="no">
  501. <xsl:copy-of select="@*"/>
  502. <xsl:apply-templates mode="grapht:fid" select="@*"/>
  503. <xsl:apply-templates mode="grapht:analyze_nodes.paths.unique"/>
  504. </xsl:copy>
  505. </xsl:template>
  506. <xsl:template match="grapht:analyze_fid" mode="grapht:analyze_nodes.paths.unique">
  507. <xsl:copy copy-namespaces="no">
  508. <xsl:copy-of select="@*"/>
  509. <xsl:for-each select="grapht:analyze_nodes.tree">
  510. <xsl:copy copy-namespaces="no">
  511. <xsl:copy-of select="@*"/>
  512. <xsl:variable name="grapht:anchestor.count" select="@grapht:anchestor.count"/>
  513. <xsl:variable name="current.parent.fid" select="@grapht:fid"/>
  514. <xsl:message>#437 mode grapht:analyze_nodes.paths.unique @grapht:fid=<xsl:value-of select="@grapht:fid"/>; </xsl:message>
  515. <xsl:copy-of select="grapht:analyze_nodes.tree.clousure"/>
  516. <grapht:analyze_nodes.tree.clousure.referred>
  517. <xsl:attribute name="debug.452.current.parent.fid" select="$current.parent.fid"/>
  518. <xsl:attribute name="grapht:anchestor.count" select="$grapht:anchestor.count"/>
  519. <xsl:for-each select="root()//*[grapht:analyze_nodes.tree.clousure[grapht:path[@grapht:fid = $current.parent.fid]]]">
  520. <xsl:copy copy-namespaces="no">
  521. <xsl:attribute name="grapht:path.len" select=" number($grapht:anchestor.count) - number(@grapht:anchestor.count)"/>
  522. <xsl:copy-of select="@*"/>
  523. </xsl:copy>
  524. </xsl:for-each>
  525. </grapht:analyze_nodes.tree.clousure.referred>
  526. </xsl:copy>
  527. </xsl:for-each>
  528. </xsl:copy>
  529. </xsl:template>
  530. <xsl:template match="*" mode="grapht:analyze_nodes.tree.clousure.searched">
  531. <xsl:param name="current.parent.fid" required="yes"/>
  532. <xsl:param name="grapht:fid" required="yes"/>
  533. <xsl:param name="grapht:path" select="1"/>
  534. <xsl:choose>
  535. <xsl:when test="descendant-or-self::*[@grapht:fid=$current.parent.fid ]"> <!-- descendant-or-self::*[@grapht:fid=$current.parent.fid ] --> <!-- key('descendant-or-self',$current.parent.fid) -->
  536. <xsl:for-each select="descendant::*[@grapht:fid=$current.parent.fid ][1]"> <!-- descendant::*[@grapht:fid=$current.parent.fid ][1] --> <!-- key('descendant-or-self',$current.parent.fid)[1] -->
  537. <grapht:path_step>
  538. <!--<xsl:copy-of select="@grapht:fid"/>-->
  539. <xsl:copy-of select="@p5:primaryKey"/>
  540. <xsl:attribute name="local-name" select="local-name()"/>
  541. </grapht:path_step>
  542. </xsl:for-each>
  543. <grapht:path_info>
  544. <xsl:attribute name="grapht:when" select="'descendant-or-self'"/>
  545. <xsl:attribute name="grapht:path" select="$grapht:path"/>
  546. <xsl:attribute name="grapht:node_from" select="@grapht:fid"/>
  547. </grapht:path_info>
  548. </xsl:when>
  549. <xsl:otherwise>
  550. <grapht:path_step>
  551. <!--<xsl:copy-of select="@grapht:fid"/>-->
  552. <xsl:copy-of select="@p5:primaryKey"/>
  553. <xsl:attribute name="local-name" select="local-name()"/>
  554. </grapht:path_step>
  555. <!--<xsl:message>#552 going parent to search by grapht:path=<xsl:value-of select="$grapht:path"/>;</xsl:message>-->
  556. <xsl:apply-templates mode="grapht:analyze_nodes.tree.clousure.searched" select="parent::node()">
  557. <xsl:with-param name="current.parent.fid" select="$current.parent.fid"/>
  558. <xsl:with-param name="grapht:fid" select="$grapht:fid"/>
  559. <xsl:with-param name="grapht:path" select="number($grapht:path) + 1"/>
  560. </xsl:apply-templates>
  561. </xsl:otherwise>
  562. </xsl:choose>
  563. </xsl:template>
  564. </xsl:stylesheet>