p5dkp.true.path.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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. xmlns:p5dkp="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/dita_kosztorys_projektowy/p5dkp.xsd"
  5. exclude-result-prefixes="xs"
  6. version="2.0">
  7. <xsl:function name="p5dkp:true.path">
  8. <xsl:param name="p5dkp:href"/> <!-- to calculate real path from like file:/Users/a.binder/procesy5-dita-templates-druki/MATRYCA_PROJEKTU_BUDZET_ETAP_ROLA_PRACOWNIK/zalozenia_projektowe///../role//../szablony/rola.dita -->
  9. <xsl:variable name="path" select="p5dkp:true.path.variable($p5dkp:href)"/>
  10. <xsl:variable name="test">
  11. <test>
  12. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash">
  13. <slash>
  14. <xsl:copy-of select="@*"/>
  15. <xsl:variable name="next.min.parent.pos" select="min($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  16. <xsl:variable name="next.min.path.pos" select="min($path//slash[ text() and number(@pos) &gt; current()/@pos ]/@pos)"/>
  17. <xsl:variable name="next.min.parent.pos.count" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  18. <xsl:variable name="next.min.parent.pos.count.path" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos and number(@pos) &lt; $next.min.path.pos]/@pos)"/>
  19. <xsl:attribute name="next.min.parent.pos" select="$next.min.parent.pos"/>
  20. <xsl:attribute name="next.min.path.pos" select="$next.min.path.pos"/>
  21. <xsl:attribute name="next.min.parent.pos.count" select="$next.min.parent.pos.count"/>
  22. <xsl:attribute name="next.min.parent.pos.count.path" select="$next.min.parent.pos.count.path"/>
  23. <xsl:if test="text()"><xsl:attribute name="text" select="text()"/></xsl:if>
  24. <!--<xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]next.min.parent.pos=</xsl:text><xsl:value-of select="$next.min.parent.pos"/><xsl:text> ,next.min.path.pos</xsl:text><xsl:value-of select="$next.min.path.pos"/><xsl:text> ,next.min.parent.pos.count</xsl:text><xsl:value-of select="$next.min.parent.pos.count"/><xsl:text>, next.min.parent.pos.count.path=</xsl:text><xsl:value-of select="$next.min.parent.pos.count.path"/><xsl:if test="@parent"><xsl:text> @parent </xsl:text></xsl:if><xsl:if test="@ignore"><xsl:text> @ignore </xsl:text></xsl:if><xsl:text> [ </xsl:text><xsl:value-of select="text()"/><xsl:text> ]</xsl:text>-->
  25. <xsl:choose>
  26. <xsl:when test="@ignore"/>
  27. <xsl:when test="@parent"/>
  28. <!--<xsl:when test="$next.min.parent.pos.count.path &gt; 1"><!-\-<xsl:text>../</xsl:text>-\-></xsl:when>-->
  29. <!--<xsl:when test="$next.min.parent.pos &lt; $next.min.path.pos"/>--> <!-- ignored@pos=<xsl:value-of select="@pos"/>;<xsl:value-of select="."/><xsl:text>/</xsl:text>$next.min.parent.pos=<xsl:value-of select="$next.min.parent.pos"/>;next.min.path.pos=<xsl:value-of select="$next.min.path.pos"/> -->
  30. <xsl:otherwise>
  31. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  32. </xsl:otherwise>
  33. </xsl:choose>
  34. </slash>
  35. </xsl:for-each>
  36. </test>
  37. </xsl:variable>
  38. <xsl:variable name="next.min.path.pos" select="min($test//slash[ text()]/number(@pos))"/><!-- najmniejsze dane -->
  39. <xsl:variable name="min.next.min.parent.pos" select="min($test//slash[ @parent ]/number(@pos))"/> <!-- najmniejsze parent -->
  40. <xsl:variable name="min.next.min.parent.pos.count.path" select="min($test//slash[number(@next.min.parent.pos.count.path) &gt; 0 and not(@ignore) ]/number(@pos))"/> <!-- najmniejszy element gdzie potem jest parent --> <!-- and number(@pos) &gt; $next.min.path.pos -->
  41. <xsl:variable name="min.next.min.parent.pos.count.path.pos" select="max($test//slash[ number(@pos) &lt; $min.next.min.parent.pos.count.path and text() ]/number(@pos))"/><!-- j.w. ale z danymi -->
  42. <xsl:variable name="return">
  43. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash[number(@pos) &lt; $min.next.min.parent.pos and number(@pos) &gt;= $next.min.path.pos and number(@pos) &lt; $min.next.min.parent.pos.count.path and number(@pos) &lt;= $min.next.min.parent.pos.count.path.pos ]">
  44. <xsl:choose>
  45. <xsl:when test="@ignore"/>
  46. <xsl:when test="@parent"/>
  47. <xsl:otherwise>
  48. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  49. </xsl:otherwise>
  50. </xsl:choose>
  51. </xsl:for-each>
  52. </xsl:variable>
  53. <xsl:variable name="rest" >
  54. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash[number(@pos) &gt; $min.next.min.parent.pos and number(@pos) &gt; $min.next.min.parent.pos.count.path ]">
  55. <!--<xsl:if test="position() = 1">
  56. <xsl:text>/..</xsl:text>
  57. </xsl:if>-->
  58. <xsl:choose>
  59. <xsl:when test="@ignore"/>
  60. <xsl:when test="@parent"><xsl:text>/..</xsl:text></xsl:when>
  61. <xsl:otherwise>
  62. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:for-each>
  66. </xsl:variable>
  67. <!--<xsl:message>#133 $path = <xsl:copy-of select="$path" copy-namespaces="no"/></xsl:message>-->
  68. <xsl:choose>
  69. <xsl:when test="$min.next.min.parent.pos &lt; 1 or not($min.next.min.parent.pos)">
  70. <xsl:value-of select="replace($p5dkp:href,'//','/')"/>
  71. </xsl:when>
  72. <xsl:when test="$rest/text()">
  73. <xsl:value-of select="p5dkp:true.path(replace(concat($return,$rest),'//','/'))"/>
  74. </xsl:when>
  75. </xsl:choose>
  76. <!--<result>
  77. <xsl:attribute name="min.next.min.parent.pos.count.path" select="$min.next.min.parent.pos.count.path"/>
  78. <xsl:attribute name="min.next.min.parent.pos.count.path.pos" select="$min.next.min.parent.pos.count.path.pos"/>
  79. <xsl:attribute name="min.next.min.parent.pos" select="$min.next.min.parent.pos"/>
  80. <xsl:attribute name="return" select="$return"/>
  81. <xsl:choose>
  82. <xsl:when test="$min.next.min.parent.pos &lt; 1 or not($min.next.min.parent.pos)">
  83. <xsl:attribute name="return_final" select="$p5dkp:href"/>
  84. </xsl:when>
  85. <xsl:when test="$rest/text()">
  86. <xsl:attribute name="rest" select="$rest"/>
  87. <LOOP_REST>
  88. <xsl:copy-of select="p5dkp:true.path_TEST_2(concat($return,$rest))" copy-namespaces="no"/>
  89. </LOOP_REST>
  90. </xsl:when>
  91. </xsl:choose>
  92. <xsl:copy-of select="p5dkp:true.path.variable($p5dkp:href)"/>
  93. <xsl:copy-of select="$test"/>
  94. <return><xsl:value-of select="$return"/></return>
  95. </result>-->
  96. </xsl:function>
  97. <xsl:function name="p5dkp:true.path_TEST_2">
  98. <xsl:param name="p5dkp:href"/> <!-- to calculate real path from like file:/Users/a.binder/procesy5-dita-templates-druki/MATRYCA_PROJEKTU_BUDZET_ETAP_ROLA_PRACOWNIK/zalozenia_projektowe///../role//../szablony/rola.dita -->
  99. <xsl:param name="loop" />
  100. <xsl:variable name="path" select="p5dkp:true.path.variable($p5dkp:href)"/>
  101. <xsl:variable name="test">
  102. <test>
  103. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash">
  104. <slash>
  105. <xsl:copy-of select="@*"/>
  106. <xsl:variable name="next.min.parent.pos" select="min($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  107. <xsl:variable name="next.min.path.pos" select="min($path//slash[ text() and number(@pos) &gt; current()/@pos ]/@pos)"/>
  108. <xsl:variable name="next.min.parent.pos.count" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  109. <xsl:variable name="next.min.parent.pos.count.path" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos and number(@pos) &lt; $next.min.path.pos]/@pos)"/>
  110. <xsl:attribute name="next.min.parent.pos" select="$next.min.parent.pos"/>
  111. <xsl:attribute name="next.min.path.pos" select="$next.min.path.pos"/>
  112. <xsl:attribute name="next.min.parent.pos.count" select="$next.min.parent.pos.count"/>
  113. <xsl:attribute name="next.min.parent.pos.count.path" select="$next.min.parent.pos.count.path"/>
  114. <xsl:if test="text()"><xsl:attribute name="text" select="text()"/></xsl:if>
  115. <!--<xsl:text>[</xsl:text><xsl:value-of select="position()"/><xsl:text>]next.min.parent.pos=</xsl:text><xsl:value-of select="$next.min.parent.pos"/><xsl:text> ,next.min.path.pos</xsl:text><xsl:value-of select="$next.min.path.pos"/><xsl:text> ,next.min.parent.pos.count</xsl:text><xsl:value-of select="$next.min.parent.pos.count"/><xsl:text>, next.min.parent.pos.count.path=</xsl:text><xsl:value-of select="$next.min.parent.pos.count.path"/><xsl:if test="@parent"><xsl:text> @parent </xsl:text></xsl:if><xsl:if test="@ignore"><xsl:text> @ignore </xsl:text></xsl:if><xsl:text> [ </xsl:text><xsl:value-of select="text()"/><xsl:text> ]</xsl:text>-->
  116. <xsl:choose>
  117. <xsl:when test="@ignore"/>
  118. <xsl:when test="@parent"/>
  119. <!--<xsl:when test="$next.min.parent.pos.count.path &gt; 1"><!-\-<xsl:text>../</xsl:text>-\-></xsl:when>-->
  120. <!--<xsl:when test="$next.min.parent.pos &lt; $next.min.path.pos"/>--> <!-- ignored@pos=<xsl:value-of select="@pos"/>;<xsl:value-of select="."/><xsl:text>/</xsl:text>$next.min.parent.pos=<xsl:value-of select="$next.min.parent.pos"/>;next.min.path.pos=<xsl:value-of select="$next.min.path.pos"/> -->
  121. <xsl:otherwise>
  122. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  123. </xsl:otherwise>
  124. </xsl:choose>
  125. </slash>
  126. </xsl:for-each>
  127. </test>
  128. </xsl:variable>
  129. <xsl:variable name="next.min.path.pos" select="min($test//slash[ text()]/number(@pos))"/><!-- najmniejsze dane -->
  130. <xsl:variable name="min.next.min.parent.pos" select="min($test//slash[ @parent ]/number(@pos))"/> <!-- najmniejsze parent -->
  131. <xsl:variable name="min.next.min.parent.pos.count.path" select="min($test//slash[number(@next.min.parent.pos.count.path) &gt; 0 and not(@ignore) ]/number(@pos))"/> <!-- najmniejszy element gdzie potem jest parent --> <!-- and number(@pos) &gt; $next.min.path.pos -->
  132. <xsl:variable name="min.next.min.parent.pos.count.path.pos" select="max($test//slash[ number(@pos) &lt; $min.next.min.parent.pos.count.path and text() ]/number(@pos))"/>
  133. <xsl:variable name="return">
  134. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash[number(@pos) &lt; $min.next.min.parent.pos and number(@pos) &gt;= $next.min.path.pos and number(@pos) &lt; $min.next.min.parent.pos.count.path and number(@pos) &lt;= $min.next.min.parent.pos.count.path.pos ]">
  135. <xsl:choose>
  136. <xsl:when test="@ignore"/>
  137. <xsl:when test="@parent"/>
  138. <xsl:otherwise>
  139. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  140. </xsl:otherwise>
  141. </xsl:choose>
  142. </xsl:for-each>
  143. </xsl:variable>
  144. <xsl:variable name="rest" >
  145. <xsl:for-each select="p5dkp:true.path.variable($p5dkp:href)//slash[number(@pos) &gt; $min.next.min.parent.pos and number(@pos) &gt; $min.next.min.parent.pos.count.path ]">
  146. <!--<xsl:if test="position() = 1">
  147. <xsl:text>/..</xsl:text>
  148. </xsl:if>-->
  149. <xsl:choose>
  150. <xsl:when test="@ignore"/>
  151. <xsl:when test="@parent"><xsl:text>/..</xsl:text></xsl:when>
  152. <xsl:otherwise>
  153. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  154. </xsl:otherwise>
  155. </xsl:choose>
  156. </xsl:for-each>
  157. </xsl:variable>
  158. <!--<xsl:message>#133 $path = <xsl:copy-of select="$path" copy-namespaces="no"/></xsl:message>-->
  159. <result_2>
  160. <xsl:attribute name="loop" select="$loop"/>
  161. <xsl:attribute name="min.next.min.parent.pos.count.path" select="$min.next.min.parent.pos.count.path"/>
  162. <xsl:attribute name="min.next.min.parent.pos.count.path.pos" select="$min.next.min.parent.pos.count.path.pos"/>
  163. <xsl:attribute name="min.next.min.parent.pos" select="$min.next.min.parent.pos"/>
  164. <xsl:attribute name="return" select="$return"/>
  165. <xsl:choose>
  166. <xsl:when test="$min.next.min.parent.pos &lt; 1 or not($min.next.min.parent.pos)">
  167. <xsl:attribute name="return_final" select="$p5dkp:href"/>
  168. </xsl:when>
  169. <xsl:when test="$rest/text()">
  170. <xsl:attribute name="rest" select="$rest"/>
  171. <LOOP_REST_2>
  172. <xsl:attribute name="loop" select="$loop"/>
  173. <xsl:choose>
  174. <xsl:when test="$loop &lt; 6">
  175. <xsl:copy-of select="p5dkp:true.path_TEST_2(concat($return,$rest),$loop + 1)" copy-namespaces="no"/>
  176. </xsl:when>
  177. </xsl:choose>
  178. </LOOP_REST_2>
  179. </xsl:when>
  180. </xsl:choose>
  181. <xsl:copy-of select="p5dkp:true.path.variable($p5dkp:href)"/>
  182. <xsl:copy-of select="$test"/>
  183. <return>
  184. <xsl:attribute name="loop" select="$loop"/>
  185. <xsl:value-of select="$return"/>
  186. </return>
  187. </result_2>
  188. </xsl:function>
  189. <xsl:function name="p5dkp:true.path.variable">
  190. <xsl:param name="p5dkp:href"/>
  191. <path>
  192. <xsl:for-each select="tokenize($p5dkp:href,'/')">
  193. <slash>
  194. <xsl:attribute name="pos" select="position()"/>
  195. <xsl:choose>
  196. <xsl:when test="current() = '..'">
  197. <xsl:attribute name="parent" select="true()"/>
  198. </xsl:when>
  199. <xsl:when test="string-length(.) &gt; 0 ">
  200. <xsl:value-of select="."/>
  201. </xsl:when>
  202. <xsl:when test="string-length(.) &gt; 0 ">
  203. <xsl:value-of select="."/>
  204. </xsl:when>
  205. <xsl:otherwise>
  206. <xsl:attribute name="ignore" select="true()"/>
  207. </xsl:otherwise>
  208. </xsl:choose>
  209. </slash>
  210. </xsl:for-each>
  211. </path>
  212. </xsl:function>
  213. <!--<xsl:function name="p5dkp:true.path">
  214. <xsl:param name="p5dkp:href"/> <!-\- to calculate real path from like file:/Users/a.binder/procesy5-dita-templates-druki/MATRYCA_PROJEKTU_BUDZET_ETAP_ROLA_PRACOWNIK/zalozenia_projektowe///../role//../szablony/rola.dita -\->
  215. <xsl:variable name="path">
  216. <path>
  217. <xsl:for-each select="tokenize($p5dkp:href,'/')">
  218. <slash>
  219. <xsl:attribute name="pos" select="position()"/>
  220. <xsl:choose>
  221. <xsl:when test="current() = '..'">
  222. <xsl:attribute name="parent" select="true()"/>
  223. </xsl:when>
  224. <xsl:when test="string-length(.) &gt; 0 ">
  225. <xsl:value-of select="."/>
  226. </xsl:when>
  227. <xsl:otherwise>
  228. <xsl:attribute name="ignore" select="true()"/>
  229. </xsl:otherwise>
  230. </xsl:choose>
  231. </slash>
  232. </xsl:for-each>
  233. </path>
  234. </xsl:variable>
  235. <!-\-<xsl:copy-of select="$path"/>-\->
  236. <xsl:variable name="return">
  237. <xsl:for-each select="$path//slash">
  238. <xsl:variable name="next.min.parent.pos" select="min($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  239. <xsl:variable name="next.min.path.pos" select="min($path//slash[ text() and number(@pos) &gt; current()/@pos ]/@pos)"/>
  240. <xsl:variable name="next.min.parent.pos.count" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos ]/@pos)"/>
  241. <xsl:variable name="next.min.parent.pos.count.path" select="count($path//slash[@parent and number(@pos) &gt; current()/@pos and number(@pos) &lt; $next.min.path.pos]/@pos)"/>
  242. <xsl:choose>
  243. <xsl:when test="@ignore"/>
  244. <xsl:when test="@parent"/>
  245. <!-\-<xsl:when test="$next.min.parent.pos.count.path &gt; 1"><xsl:text>/..</xsl:text></xsl:when>-\->
  246. <xsl:when test="$next.min.parent.pos &lt; $next.min.path.pos"/> <!-\- ignored@pos=<xsl:value-of select="@pos"/>;<xsl:value-of select="."/><xsl:text>/</xsl:text>$next.min.parent.pos=<xsl:value-of select="$next.min.parent.pos"/>;next.min.path.pos=<xsl:value-of select="$next.min.path.pos"/> -\->
  247. <xsl:otherwise>
  248. <xsl:text>/</xsl:text><xsl:value-of select="text()"/>
  249. </xsl:otherwise>
  250. </xsl:choose>
  251. </xsl:for-each>
  252. </xsl:variable>
  253. <!-\-<xsl:message>#133 $path = <xsl:copy-of select="$path" copy-namespaces="no"/></xsl:message>-\->
  254. <xsl:value-of select="$return"/>
  255. </xsl:function>-->
  256. </xsl:stylesheet>