p5dkp.fix-topic.xsl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. xmlns:p5bws="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/WPS_Functions.xsd"
  5. xmlns:system_cache__appinfo="http://biuro.biall-net.pl/xmlschema_procesy5/default_db_xml_cache/appinfo.xsd"
  6. xmlns:p5dkp="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/dita_kosztorys_projektowy/p5dkp.xsd"
  7. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  8. xmlns:p5suis="http://biuro.biall-net.pl/xmlschema_procesy5/WPS_Functions/system_ui_info_speech/system_ui_info_speech.xsd"
  9. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  10. xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
  11. exclude-result-prefixes="xs vc p5bws system_cache__appinfo p5suis p5dkp ditaarch xsi"
  12. version="2.0">
  13. <!--<xsl:output indent="yes" method="xml" standalone="no" doctype-public="-//OASIS//DTD DITA Topic//EN" doctype-system="topic.dtd"/>-->
  14. <xsl:output indent="yes" />
  15. <xsl:strip-space elements="*"/>
  16. <!--<xsl:variable name="debug" select="99"/>-->
  17. <xsl:template mode="p5dkp:fix-topic" match="topic">
  18. <xsl:param name="keyscope" required="yes"/>
  19. <xsl:param name="map.path" required="yes"/>
  20. <xsl:param name="keyscope.attr" required="yes"/>
  21. <xsl:param name="keydef" required="yes"/>
  22. <xsl:param name="href" required="yes"/>
  23. <p5dkp:fix-topic>
  24. <xsl:attribute name="map.path" select="$map.path"/>
  25. <xsl:choose>
  26. <xsl:when test="$debug">
  27. <xsl:copy-of select="@*"/>
  28. <keyscope.attr>
  29. <xsl:copy-of select="$keyscope.attr"/>
  30. </keyscope.attr>
  31. <keydef>
  32. <xsl:copy-of select="$keydef"/>
  33. </keydef>
  34. <keyscope>
  35. <xsl:copy-of select="$keyscope"/>
  36. </keyscope>
  37. <href>
  38. <xsl:value-of select="$href"/>
  39. </href>
  40. </xsl:when>
  41. </xsl:choose>
  42. <xsl:variable name="context" select="."/>
  43. <xsl:variable name="max_keyscope" select="max($keyscope//key/string-length(text()))"/>
  44. <!--<max_keyscope>
  45. <xsl:value-of select="$max_keyscope"/>
  46. </max_keyscope>-->
  47. <xsl:for-each select="$keyscope//key">
  48. <xsl:choose>
  49. <xsl:when test="string-length(.) = $max_keyscope">
  50. <xsl:for-each select="tokenize( . , '\.')">
  51. <xsl:choose>
  52. <xsl:when test="position() = 1">
  53. <xsl:choose>
  54. <xsl:when test="current() = 'role'">
  55. <xsl:variable name="p5dkp:fix-topic.role">
  56. <xsl:apply-templates mode="p5dkp:fix-topic.role" select="$context">
  57. <xsl:with-param name="keydef" select="$keydef"/>
  58. <xsl:with-param name="keyscope" select="$keyscope"/>
  59. </xsl:apply-templates>
  60. </xsl:variable>
  61. <xsl:choose>
  62. <xsl:when test="$p5dkp:fix-topic.role//comment()">
  63. <p5suis:say> Fixed dita to copy <xsl:value-of select="$href"/></p5suis:say>
  64. <xsl:message>#65 Fixed dita to copy <xsl:value-of select="$map.path"/>/<xsl:value-of select="$href"/> </xsl:message>
  65. <xsl:result-document href="{$map.path}/{$href}.fixed">
  66. <xsl:copy-of select="$p5dkp:fix-topic.role"/>
  67. </xsl:result-document>
  68. </xsl:when>
  69. </xsl:choose>
  70. </xsl:when>
  71. <xsl:when test="current() = 'wymagania'">
  72. <xsl:variable name="p5dkp:fix-topic.wymagania">
  73. <xsl:apply-templates mode="p5dkp:fix-topic.wymagania" select="$context">
  74. <xsl:with-param name="keydef" select="$keydef"/>
  75. <xsl:with-param name="keyscope" select="$keyscope"/>
  76. </xsl:apply-templates>
  77. </xsl:variable>
  78. <!--<TRY_WYMAGANIA>
  79. <TEST>
  80. <xsl:copy-of select="$p5dkp:fix-topic.wymagania"/>
  81. </TEST>
  82. <CONTEXT>
  83. <xsl:copy-of select="$context"/>
  84. </CONTEXT>
  85. </TRY_WYMAGANIA>-->
  86. <xsl:choose>
  87. <xsl:when test="$p5dkp:fix-topic.wymagania//comment()">
  88. <p5suis:say> Fixed dita to copy <xsl:value-of select="$href"/></p5suis:say>
  89. <xsl:message>#82 Fixed dita to copy <xsl:value-of select="$map.path"/>/<xsl:value-of select="$href"/> </xsl:message>
  90. <xsl:choose>
  91. <xsl:when test="doc-available(concat($map.path,'/',$href,'.fixed'))">
  92. <xsl:message>#102 DOCUMENT EXISTS - should bbefore go clean! <xsl:value-of select="$href"/>.fixed !!</xsl:message>
  93. </xsl:when>
  94. <xsl:otherwise>
  95. <xsl:result-document href="{$map.path}/{$href}.fixed">
  96. <xsl:copy-of select="$p5dkp:fix-topic.wymagania"/>
  97. </xsl:result-document>
  98. </xsl:otherwise>
  99. </xsl:choose>
  100. </xsl:when>
  101. </xsl:choose>
  102. </xsl:when>
  103. </xsl:choose>
  104. </xsl:when>
  105. </xsl:choose>
  106. </xsl:for-each>
  107. </xsl:when>
  108. </xsl:choose>
  109. </xsl:for-each>
  110. </p5dkp:fix-topic>
  111. </xsl:template>
  112. <xsl:template mode="p5dkp:fix-topic.role p5dkp:fix-topic.wymagania" match="*">
  113. <xsl:param name="keyscope" required="yes"/>
  114. <xsl:param name="keydef" required="yes"/>
  115. <xsl:copy>
  116. <xsl:copy-of select="@*"/>
  117. <xsl:apply-templates mode="#current">
  118. <xsl:with-param name="keydef" select="$keydef"/>
  119. <xsl:with-param name="keyscope" select="$keyscope"/>
  120. </xsl:apply-templates>
  121. </xsl:copy>
  122. </xsl:template>
  123. <!--<xsl:template mode="p5dkp:fix-topic.role p5dkp:fix-topic.wymagania" match="*">
  124. <xsl:param name="keyscope" required="yes"/>
  125. <xsl:param name="keydef" required="yes"/>
  126. <xsl:copy>
  127. <xsl:copy-of select="@*"/>
  128. <xsl:apply-templates mode="#current">
  129. <xsl:with-param name="keydef" select="$keydef"/>
  130. <xsl:with-param name="keyscope" select="$keyscope"/>
  131. </xsl:apply-templates>
  132. </xsl:copy>
  133. </xsl:template>-->
  134. <xsl:template mode="p5dkp:fix-topic.role p5dkp:fix-topic.wymagania" match="body[preceding-sibling::title[ ph[@keyref='wymagania_no'] ]]" priority="9">
  135. <xsl:message>#140 bypassing due to topic specyfing keys in custom style </xsl:message>
  136. </xsl:template>
  137. <xsl:template mode="p5dkp:fix-topic.role" match="body[ not( p ) or not(p[table]) ]">
  138. <xsl:param name="keyscope" required="yes"/>
  139. <xsl:param name="keydef" required="yes"/>
  140. <xsl:message>#73 TO FIX <xsl:value-of select="@*"/></xsl:message>
  141. <xsl:copy>
  142. <xsl:copy-of select="@*"/>
  143. <xsl:comment>#80 FIX FIX</xsl:comment>
  144. <p>
  145. <table>
  146. <tgroup cols="3">
  147. <thead>
  148. <row>
  149. <entry>role</entry>
  150. <entry>descr</entry>
  151. <entry>cost month</entry>
  152. </row>
  153. </thead>
  154. <tbody>
  155. <row>
  156. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_no"/></entry>
  157. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_desc"/></entry>
  158. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_price"/></entry>
  159. </row>
  160. </tbody>
  161. </tgroup>
  162. </table>
  163. </p>
  164. <xsl:apply-templates mode="#current">
  165. <xsl:with-param name="keydef" select="$keydef"/>
  166. <xsl:with-param name="keyscope" select="$keyscope"/>
  167. </xsl:apply-templates>
  168. </xsl:copy>
  169. </xsl:template>
  170. <xsl:function name="p5dkp:max_keyscope.pos">
  171. <xsl:param name="p5dkp:keyscope"/>
  172. <xsl:variable name="max_keyscope" select="max($p5dkp:keyscope//key/string-length(text()))"/>
  173. <xsl:for-each select="$p5dkp:keyscope//key">
  174. <xsl:if test="string-length(text()) = $max_keyscope">
  175. <xsl:value-of select="position()"/>
  176. </xsl:if>
  177. </xsl:for-each>
  178. </xsl:function>
  179. <xsl:function name="p5dkp:max_keyscope.get">
  180. <xsl:param name="p5dkp:keyscope"/>
  181. <xsl:param name="p5dkp:max_keyscope.pos"/>
  182. <xsl:if test="number($debug) &gt; 4"><xsl:message>#190 $p5dkp:max_keyscope.pos = <xsl:value-of select="$p5dkp:max_keyscope.pos"/>
  183. <xsl:copy-of select="$p5dkp:keyscope//key[round($p5dkp:max_keyscope.pos)]" copy-namespaces="no"/>
  184. </xsl:message></xsl:if>
  185. <xsl:choose>
  186. <xsl:when test="contains($p5dkp:keyscope//key[ round($p5dkp:max_keyscope.pos)]/text(),' ')">
  187. <xsl:for-each select="tokenize($p5dkp:keyscope//key[ round($p5dkp:max_keyscope.pos)]/text(),' ')[1]">
  188. <xsl:value-of select="."/>
  189. </xsl:for-each>
  190. </xsl:when>
  191. <xsl:otherwise><xsl:value-of select="$p5dkp:keyscope//key[ round($p5dkp:max_keyscope.pos)]/text()"/></xsl:otherwise>
  192. </xsl:choose>
  193. </xsl:function>
  194. <xsl:template mode="p5dkp:fix-topic.wymagania" match="body[ not( p ) or not(p[simpletable]) ]">
  195. <xsl:param name="keyscope" required="yes"/>
  196. <xsl:param name="keydef" required="yes"/>
  197. <xsl:message>#167 TO FIX <xsl:value-of select="@*"/></xsl:message>
  198. <xsl:copy>
  199. <xsl:copy-of select="@*"/>
  200. <xsl:comment>#167 FIX FIX</xsl:comment>
  201. <p>
  202. <simpletable frame="all" relcolwidth="1* 1* 1* 1* 1* 1*" >
  203. <sthead>
  204. <stentry>Przydzielona rola</stentry>
  205. <stentry>Opis Zadanis</stentry>
  206. <stentry>Koszt</stentry>
  207. <stentry>nakład godzin</stentry>
  208. <stentry>wymiar czasu</stentry>
  209. <stentry>etap</stentry>
  210. </sthead>
  211. <strow>
  212. <!--<xsl:variable name="max_keyscope" select="max($keyscope//key/string-length(text()))"/>
  213. <xsl:variable name="max_keyscope.pos">
  214. <xsl:for-each select="$keyscope//key">
  215. <xsl:if test="string-length(text()) = $max_keyscope">
  216. <xsl:value-of select="position()"/>
  217. </xsl:if>
  218. </xsl:for-each>
  219. </xsl:variable>-->
  220. <xsl:variable name="max_keyscope.pos" select="p5dkp:max_keyscope.pos($keyscope)"/>
  221. <stentry><xref keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.role_no"/>
  222. <!--<ph keyref="wymagania.ogolne.harmonotram.role_no"/>--></stentry>
  223. <stentry>
  224. <ph keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.role_desc"/></stentry>
  225. <stentry>
  226. <ph keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.role_price"/>
  227. </stentry>
  228. <stentry>
  229. <ph keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.role_time"/>
  230. </stentry>
  231. <stentry>
  232. <ph keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.role_price_recur"/>
  233. </stentry>
  234. <stentry>
  235. <ph keyref="{p5dkp:max_keyscope.get($keyscope,$max_keyscope.pos)}.etap_no"/>
  236. </stentry>
  237. </strow>
  238. </simpletable>
  239. </p>
  240. <xsl:apply-templates mode="#current">
  241. <xsl:with-param name="keydef" select="$keydef"/>
  242. <xsl:with-param name="keyscope" select="$keyscope"/>
  243. </xsl:apply-templates>
  244. </xsl:copy>
  245. </xsl:template>
  246. <!--<xsl:template mode="p5dkp:fix-topic.role" match="title">
  247. <TITLE>
  248. <xsl:value-of select="ph[ not( contains(@keyref,'role.'))]"/>
  249. </TITLE>
  250. </xsl:template>-->
  251. <xsl:template mode="p5dkp:fix-topic.role" match="title[ ph[ not( contains(@keyref,'role.'))] ]">
  252. <xsl:param name="keyscope" required="yes"/>
  253. <xsl:param name="keydef" required="yes"/>
  254. <xsl:copy>
  255. <xsl:copy-of select="@*"/>
  256. <!--<FIX>-->
  257. <xsl:apply-templates mode="p5dkp:fix-topic.role.title">
  258. <xsl:with-param name="keydef" select="$keydef"/>
  259. <xsl:with-param name="keyscope" select="$keyscope"/>
  260. </xsl:apply-templates>
  261. <!--</FIX>-->
  262. </xsl:copy>
  263. </xsl:template>
  264. <xsl:template mode="p5dkp:fix-topic.wymagania" match="title[ ph[ contains(@keyref,'map.descr')] ]">
  265. <xsl:param name="keyscope" required="yes"/>
  266. <xsl:param name="keydef" required="yes"/>
  267. <xsl:copy>
  268. <xsl:copy-of select="@*"/>
  269. <!--<FIX1111>-->
  270. <xsl:apply-templates mode="p5dkp:fix-topic.wymagania.title">
  271. <xsl:with-param name="keydef" select="$keydef"/>
  272. <xsl:with-param name="keyscope" select="$keyscope"/>
  273. </xsl:apply-templates>
  274. <!--</FIX1111>-->
  275. </xsl:copy>
  276. </xsl:template>
  277. <xsl:template mode="p5dkp:fix-topic.role.title p5dkp:fix-topic.wymagania.title" match="text()">
  278. <xsl:copy-of select="."/>
  279. </xsl:template>
  280. <xsl:template mode="p5dkp:fix-topic.role.title" match="ph[contains(@keyref,'map.descr.')]">
  281. <xsl:param name="keyscope" required="yes"/>
  282. <xsl:param name="keydef" required="yes"/>
  283. <ph keyref="{$keyscope//key[ position() = last()]/text()}.role_no"/>
  284. <xsl:comment>#154 FIXED SUBJECT</xsl:comment>
  285. </xsl:template>
  286. <xsl:template mode="p5dkp:fix-topic.wymagania.title" match="ph[contains(@keyref,'map.descr')]">
  287. <xsl:param name="keyscope" required="yes"/>
  288. <xsl:param name="keydef" required="yes"/>
  289. <xsl:variable name="max_keyscope" select="max($keyscope//key/string-length(text()))"/>
  290. <xsl:variable name="max_keyscope.pos">
  291. <xsl:for-each select="$keyscope//key">
  292. <xsl:if test="string-length(text()) = $max_keyscope"><xsl:value-of select="position()"/></xsl:if>
  293. </xsl:for-each>
  294. </xsl:variable>
  295. <ph keyref="{$keyscope//key[ position() = $max_keyscope.pos]/text()}.wymagania_desc"/>
  296. <xsl:comment>#256 FIXED SUBJECT</xsl:comment>
  297. </xsl:template>
  298. <xsl:template mode="p5dkp:fix-topic.role.title p5dkp:fix-topic.wymagania.title" match="*">
  299. <xsl:copy-of select="."/>
  300. </xsl:template>
  301. <xsl:template mode="p5dkp:fix-topic.role" match="tbody[row[ not(entry[ph[contains(@keyref,'role.')] ])]]">
  302. <xsl:param name="keyscope" required="yes"/>
  303. <xsl:param name="keydef" required="yes"/>
  304. <xsl:message>#133 TO FIX <xsl:value-of select=".//@*"/></xsl:message>
  305. <xsl:comment>#133 to fix <xsl:copy-of select=".//@*"/></xsl:comment>
  306. <tbody>
  307. <row>
  308. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_no"/></entry>
  309. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_desc"/></entry>
  310. <entry><ph keyref="{$keyscope//key[ position() = last()]/text()}.role_price"/></entry>
  311. </row>
  312. </tbody>
  313. </xsl:template>
  314. <xsl:template mode="p5dkp:fix-topic.wymagania" match="strow[ stentry[xref[contains(@keyref,'map.role')] ]]">
  315. <xsl:param name="keyscope" required="yes"/>
  316. <xsl:param name="keydef" required="yes"/>
  317. <xsl:message>#1333 TO FIX <xsl:value-of select=".//@*"/></xsl:message>
  318. <strow>
  319. <xsl:variable name="max_keyscope" select="max($keyscope//key/string-length(text()))"/>
  320. <xsl:variable name="max_keyscope.pos">
  321. <xsl:for-each select="$keyscope//key">
  322. <xsl:if test="string-length(text()) = $max_keyscope"><xsl:value-of select="position()"/></xsl:if>
  323. </xsl:for-each>
  324. </xsl:variable>
  325. <xsl:comment>#133 to fix <xsl:copy-of select=".//@*"/> $max_keyscope = <xsl:value-of select="$max_keyscope"/> ; $max_keyscope.pos = <xsl:value-of select="$max_keyscope.pos"/> </xsl:comment>
  326. <stentry><xref keyref="{$keyscope//key[ $max_keyscope.pos]/text()}.role_no"/>
  327. <!--<ph keyref="wymagania.ogolne.harmonotram.role_no"/>--></stentry>
  328. <stentry>
  329. <ph keyref="{$keyscope//key[ $max_keyscope.pos]/text()}.role_desc"/></stentry>
  330. <stentry>
  331. <ph keyref="{$keyscope//key[ $max_keyscope.pos]/text()}.role_price"/>
  332. </stentry>
  333. <stentry>
  334. <ph keyref="{$keyscope//key[ $max_keyscope.pos]/text()}.role_time"/>
  335. </stentry>
  336. <stentry>
  337. <ph keyref="{$keyscope//key[ $max_keyscope.pos]/text()}.role_price_recur"/>
  338. </stentry>
  339. <stentry>
  340. <ph keyref="{$keyscope//key[$max_keyscope.pos]/text()}.etap_no"/>
  341. </stentry>
  342. </strow>
  343. </xsl:template>
  344. <xsl:template mode="p5dkp:fix-topic" match="*|comment()|text()"/>
  345. </xsl:stylesheet>