biale_plamy_joins2ways_do_paths.xsl 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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:bp="https://procesy5.pl/biale_plamy-schema.xsd"
  6. version="2.0">
  7. <xsl:param name="plamy_prefix" select="'test2'"/>
  8. <xsl:variable name="ways2joins.xml" select="concat('ways2joins',$plamy_prefix,'.xml')"/>
  9. <xsl:variable name="ways2joins" select="doc($ways2joins.xml)"/>
  10. <xsl:output indent="yes"/>
  11. <xsl:strip-space elements="*"/>
  12. <!--example input
  13. <joins2ways>
  14. <item id="0">
  15. <item id="0">0</item>
  16. <item id="1">12135</item>
  17. <item id="2">29426</item>
  18. </item>
  19. <item id="1">
  20. <item id="0">0</item>
  21. <item id="1">1</item>
  22. <item id="2">24887</item>
  23. </item>
  24. </joins2ways>
  25. -->
  26. <xsl:template match="joins2ways_z_ID_Way">
  27. <!--<xsl:variable name="EdgeWayJoinsPair_cand">
  28. <xsl:apply-templates mode="joins"/>
  29. </xsl:variable>-->
  30. <!--<xsl:variable name="joins2ways_z_ID_Way" select="."/>-->
  31. <!--<xsl:copy-of select="$EdgeWayJoinsPair_cand"></xsl:copy-of>-->
  32. <!--<xsl:choose>
  33. <xsl:when test="$EdgeWayJoinsPair_cand/EdgeWayJoinsPair_cand[@ID_Way=current()/@ID_Way]">
  34. <JESTOK></JESTOK>
  35. </xsl:when>
  36. <xsl:otherwise>
  37. </xsl:otherwise>
  38. </xsl:choose>-->
  39. <!--<xsl:copy-of select="$EdgeWayJoinsPair_cand/no_EdgeWayJoinsPair"></xsl:copy-of>-->
  40. <xsl:variable name="guess_edges">
  41. <xsl:for-each select="item">
  42. <guess_join>
  43. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  44. <xsl:variable name="ID_Way">
  45. <xsl:choose>
  46. <xsl:when test="@ID_Way"><xsl:value-of select="@ID_Way"/></xsl:when>
  47. <xsl:otherwise><xsl:value-of select="0"/></xsl:otherwise>
  48. </xsl:choose>
  49. </xsl:variable>
  50. <xsl:apply-templates select="." mode="joins_not_way">
  51. <xsl:with-param name="ID_Way" select="$ID_Way"/>
  52. </xsl:apply-templates>
  53. </guess_join>
  54. </xsl:for-each>
  55. </xsl:variable>
  56. <EdgeWayJoins>
  57. <!--<xsl:for-each-group select="$EdgeWayJoinsPair_cand/no_EdgeWayJoinsPair" group-by="@ID_Way">
  58. <EdgeWayJoinsPair>
  59. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  60. <xsl:variable name="ID_Way" select="@ID_Way"/>
  61. <xsl:variable name="Joins_miss">
  62. <xsl:for-each select="$joins2ways_z_ID_Way/item[@ID_Way=$ID_Way and count( child::node())&gt;1 ]">
  63. <!-\- szukamy joinsa ktory ma joina do innego waysa-\->
  64. <xsl:variable name="Join_ID" select="@id"/>
  65. <xsl:for-each select="item">
  66. <ways>
  67. <xsl:attribute name="id_join" select="$Join_ID"/>
  68. <xsl:attribute name="id_way" select="text()"/>
  69. </ways>
  70. </xsl:for-each>
  71. </xsl:for-each>
  72. </xsl:variable>
  73. <xsl:copy-of select="$Joins_miss"/>
  74. <xsl:variable name="Ways_miss">
  75. <xsl:for-each select="$Joins_miss/ways">
  76. <xsl:variable name="id_join" select="@id_join"/>
  77. <xsl:variable name="id_way_test" select="@id_way"/>
  78. <xsl:for-each select="$ways2joins/ways2joins/item[@id=$id_way_test]/item">
  79. <found_joins_in_ways>
  80. <xsl:attribute name="id_join" select="$id_join"/>
  81. <xsl:attribute name="id_join_found" select="text()"/>
  82. </found_joins_in_ways>
  83. </xsl:for-each>
  84. </xsl:for-each>
  85. </xsl:variable>
  86. <xsl:copy-of select="$Ways_miss"/>
  87. <xsl:for-each select="$Ways_miss/found_joins_in_ways"> <!-\- [not(@id_join_found=$EdgeJoinFound)]-\->
  88. <xsl:choose>
  89. <xsl:when test="not($Joins_miss/ways[@id_join=current()/@id_join_found])">
  90. <!-\-<missed>-\->
  91. <!-\-<xsl:attribute name="Joins" select="@id_join"/>-\->
  92. <bp:Joins>
  93. <xsl:attribute name="Joins" select="current()/@id_join_found"/>
  94. </bp:Joins>
  95. <!-\-</missed>-\->
  96. </xsl:when>
  97. </xsl:choose>
  98. </xsl:for-each>
  99. </EdgeWayJoinsPair>
  100. </xsl:for-each-group>-->
  101. <xsl:for-each-group select="item" group-by="@ID_Way">
  102. <xsl:variable name="ID_Way" select="@ID_Way"/>
  103. <EdgeWayJoinsPair>
  104. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  105. <!-- debug -->
  106. <!--<xsl:copy-of select="$guess_edges/guess_join[@ID_Way=$ID_Way]"></xsl:copy-of>-->
  107. <xsl:for-each select="$guess_edges/guess_join[@ID_Way=$ID_Way]/EdgeWayJoinsPair_cand">
  108. <bp:Joins>
  109. <xsl:attribute name="Joins" select="@joins"/>
  110. </bp:Joins>
  111. </xsl:for-each>
  112. <!--<xsl:for-each select="current-group()">
  113. <!-\-<GROUP><xsl:copy-of select="item("></xsl:copy-of></GROUP>-\->
  114. <xsl:choose>
  115. <xsl:when test=" position()=1 or position()=last()">
  116. <bp:Joins>
  117. <xsl:attribute name="Joins" select="@id"/>
  118. </bp:Joins>
  119. </xsl:when>
  120. </xsl:choose>
  121. </xsl:for-each>-->
  122. </EdgeWayJoinsPair>
  123. </xsl:for-each-group>
  124. <!--<xsl:for-each-group select="$EdgeWayJoinsPair_cand/EdgeWayJoinsPair_cand" group-by="@ID_Way">
  125. <EdgeWayJoinsPair>
  126. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  127. <xsl:variable name="ID_Way" select="@ID_Way"/>
  128. <xsl:for-each select="current-group()">
  129. <xsl:variable name="EdgeJoinFound" select="@joins"/>
  130. <bp:Joins>
  131. <xsl:attribute name="Joins" select="@joins"/>
  132. </bp:Joins>
  133. <xsl:choose>
  134. <xsl:when test=" count( current-group())&lt;2">
  135. <bp:Joins>
  136. <xsl:variable name="Joins_miss">
  137. <xsl:for-each select="$joins2ways_z_ID_Way/item[@ID_Way=$ID_Way and count( child::node())=2 ]">
  138. <!-\- szukamy joinsa ktory ma joina do innego waysa-\->
  139. <xsl:variable name="Join_ID" select="@id"/>
  140. <xsl:for-each select="item">
  141. <ways>
  142. <xsl:attribute name="id_join" select="$Join_ID"/>
  143. <xsl:attribute name="id_way" select="text()"/>
  144. </ways>
  145. </xsl:for-each>
  146. </xsl:for-each>
  147. </xsl:variable>
  148. <!-\-<xsl:copy-of select="$Joins_miss"></xsl:copy-of>-\->
  149. <xsl:variable name="Ways_miss">
  150. <xsl:for-each select="$Joins_miss/ways">
  151. <xsl:variable name="id_join" select="@id_join"/>
  152. <xsl:variable name="id_way_test" select="@id_way"/>
  153. <xsl:for-each select="$ways2joins/ways2joins/item[@id=$id_way_test]/item">
  154. <found_joins_in_ways>
  155. <xsl:attribute name="id_join" select="$id_join"/>
  156. <xsl:attribute name="id_join_found" select="text()"/>
  157. </found_joins_in_ways>
  158. </xsl:for-each>
  159. </xsl:for-each>
  160. </xsl:variable>
  161. <!-\-<xsl:copy-of select="$Ways_miss"/>-\->
  162. <xsl:for-each select="$Ways_miss/found_joins_in_ways[not(@id_join_found=$EdgeJoinFound)]">
  163. <xsl:choose>
  164. <xsl:when test="not($Joins_miss/ways[@id_join=current()/@id_join_found])">
  165. <!-\-<missed>-\->
  166. <!-\-<xsl:attribute name="Joins" select="@id_join"/>-\->
  167. <xsl:attribute name="Joins" select="current()/@id_join_found"/>
  168. <!-\-</missed>-\->
  169. </xsl:when>
  170. </xsl:choose>
  171. </xsl:for-each>
  172. </bp:Joins>
  173. </xsl:when>
  174. </xsl:choose>
  175. </xsl:for-each>
  176. </EdgeWayJoinsPair>
  177. </xsl:for-each-group>-->
  178. </EdgeWayJoins>
  179. </xsl:template>
  180. <xsl:template match="item" mode="miss_join">
  181. </xsl:template>
  182. <xsl:template match="item" mode="joins_not_way">
  183. <xsl:param name="ID_Way" required="yes"/>
  184. <xsl:variable name="count_our_way">
  185. <xsl:for-each select="item">
  186. <xsl:element name="count_our_way">
  187. <xsl:choose>
  188. <xsl:when test="@ID_WAY=$ID_Way">1</xsl:when>
  189. <xsl:otherwise>0</xsl:otherwise>
  190. </xsl:choose>
  191. </xsl:element>
  192. </xsl:for-each>
  193. </xsl:variable>
  194. <see>
  195. <xsl:copy-of select="."/>
  196. <inside>
  197. <xsl:attribute name="count_our" select="count(item[@ID_WAY=$ID_Way])"/>
  198. <count_our_way_val>
  199. <xsl:copy-of select="$count_our_way"/>
  200. </count_our_way_val>
  201. <xsl:for-each select="item[@ID_WAY!=$ID_Way]">
  202. <xsl:element name="EdgeWayJoinsPair_cand">
  203. <xsl:attribute name="joins" select="../@id"/>
  204. <xsl:attribute name="ID_Way" select="../@ID_Way"/>
  205. </xsl:element>
  206. </xsl:for-each>
  207. </inside>
  208. </see>
  209. <xsl:variable name="if_item_not_in_way">
  210. <xsl:for-each select="item">
  211. <xsl:choose>
  212. <xsl:when test="not(@ID_WAY=$ID_Way)">
  213. <xsl:element name="EdgeWayJoinsPair_cand">
  214. <xsl:attribute name="joins" select="../@id"/>
  215. <xsl:attribute name="ID_Way" select="../@ID_Way"/>
  216. </xsl:element></xsl:when>
  217. </xsl:choose>
  218. </xsl:for-each>
  219. </xsl:variable>
  220. <xsl:choose>
  221. <xsl:when test="count(item)=1">
  222. <xsl:element name="EdgeWayJoinsPair_cand">
  223. <xsl:attribute name="pos" select="position()"/>
  224. <xsl:attribute name="joins" select="@id"/>
  225. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  226. <xsl:attribute name="ways" select="item/text()"/>
  227. </xsl:element>
  228. </xsl:when>
  229. <xsl:when test="$if_item_not_in_way/EdgeWayJoinsPair_cand and count(item[@ID_WAY=$ID_Way])&lt;2">
  230. <xsl:element name="EdgeWayJoinsPair_cand">
  231. <xsl:attribute name="debug" select="'has other way'"/>
  232. <xsl:attribute name="joins" select="@id"/>
  233. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  234. <xsl:attribute name="ways">
  235. <xsl:for-each select="item/text()">
  236. <xsl:value-of select=" concat(.,' ')"/>
  237. </xsl:for-each>
  238. </xsl:attribute>
  239. <!--<xsl:attribute name="ways" select="item/text()" separator="', '" />-->
  240. </xsl:element>
  241. </xsl:when>
  242. </xsl:choose>
  243. </xsl:template>
  244. <xsl:template match="item" mode="joins">
  245. <!--<xsl:param name="second_turn" />-->
  246. <xsl:choose>
  247. <!--<xsl:when test="count(item[@ID_WAY=current()/@ID_Way])&gt;1">
  248. <xsl:element name="EdgeWayJoinsPair_cand">
  249. <xsl:attribute name="joins" select="@id"/>
  250. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  251. <xsl:attribute name="ways" select="item/text()"/>
  252. </xsl:element>
  253. </xsl:when>-->
  254. <xsl:when test="count(item)=1">
  255. <xsl:element name="EdgeWayJoinsPair_cand">
  256. <xsl:attribute name="pos" select="position()"/>
  257. <xsl:attribute name="joins" select="@id"/>
  258. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  259. <xsl:attribute name="ways" select="item/text()"/>
  260. </xsl:element>
  261. </xsl:when>
  262. <!--<xsl:when test="count(../item[@ID_Way=current()/@ID_Way]) and count( child::node()=1)">
  263. <xsl:element name="no_EdgeWayJoinsPair">
  264. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  265. </xsl:element>
  266. </xsl:when>-->
  267. <!--<xsl:when test="count(item)=2">
  268. <xsl:element name="EdgeWayJoinsPair_cand">
  269. <xsl:attribute name="joins" select="@id"/>
  270. <xsl:attribute name="ID_Way" select="@ID_Way"/>
  271. <xsl:attribute name="ways" select="item/text()"/>
  272. </xsl:element>
  273. </xsl:when>-->
  274. </xsl:choose>
  275. </xsl:template>
  276. </xsl:stylesheet>