find_child_proces.xsl 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. version="2.0">
  6. <xsl:template name="detect_outgoing">
  7. <xsl:param name="proces_id"/>
  8. <xsl:param name="parent_id"/>
  9. <xsl:param name="current_sort_prio"/>
  10. <xsl:param name="position"/>
  11. <!--
  12. Przygotowanie struktury procesow pod widok bpmn
  13. IF proces nie ma dziecka
  14. IF proces ma kolejny proces
  15. OUTPUT=kolejny proces
  16. ELSE
  17. OUTPUT=end_event
  18. ELSE output=dziecko
  19. -->
  20. <xsl:variable name="outgoings">
  21. <xsl:choose>
  22. <!-- IF proces nie ma dziecka -->
  23. <xsl:when test="not (../item[PARENT_ID=$proces_id])">
  24. <xsl:choose>
  25. <!-- IF proces ma kolejny proces nizej -->
  26. <xsl:when test="../item[PARENT_ID=$parent_id][$position+1]">
  27. <!-- out=kolejny proces -->
  28. <xsl:variable name="position_next" select="$position+1"/>
  29. <xsl:for-each select="../item[PARENT_ID=$parent_id]">
  30. <xsl:if test="position()=$position+1"> <!-- bug xslt nie mozna zrobic selecta z position! -->
  31. <xsl:element name="outgoing_id">
  32. <xsl:value-of select="ID"/>
  33. </xsl:element>
  34. <xsl:element name="outgoing_name">
  35. <xsl:value-of select="concat('Task_',ID)"/>
  36. </xsl:element>
  37. </xsl:if>
  38. </xsl:for-each>
  39. </xsl:when>
  40. <xsl:otherwise>
  41. <!-- out=end event -->
  42. <xsl:element name="outgoing_name">
  43. <xsl:value-of select="concat('EndEvent_',$proces_id)"/>
  44. </xsl:element>
  45. </xsl:otherwise>
  46. </xsl:choose>
  47. </xsl:when>
  48. <xsl:otherwise>
  49. <!-- out=dziecko -->
  50. <xsl:for-each select="../item[PARENT_ID=$proces_id and position()>$position ]">
  51. <xsl:element name="outgoing_id">
  52. <xsl:value-of select="ID"/>
  53. </xsl:element>
  54. <xsl:element name="outgoing_name">
  55. <xsl:value-of select="concat('Task_',ID)"/>
  56. </xsl:element>
  57. </xsl:for-each>
  58. <!-- TODO this is bug of engine?!?
  59. <xsl:element name="outgoing">
  60. <xsl:value-of select="../item/ID[../PARENT_ID=$proces_id ] [1]"/>
  61. </xsl:element>
  62. -->
  63. </xsl:otherwise>
  64. </xsl:choose>
  65. </xsl:variable>
  66. <xsl:variable name="GOTO_event">
  67. <xsl:for-each select="../item[ID=$proces_id and IF_TRUE_GOTO!='' and IF_TRUE_GOTO!=0 and IF_TRUE_GOTO!='0']" xpath-default-namespace="">
  68. <xsl:element name="IF_TRUE_GOTO">
  69. <xsl:element name="GOTO_ID">
  70. <xsl:value-of select="IF_TRUE_GOTO"/>
  71. </xsl:element>
  72. <xsl:element name="IF_TRUE_GOTO_FLAG">
  73. <xsl:value-of select="IF_TRUE_GOTO_FLAG"/>
  74. </xsl:element>
  75. <xsl:variable name="IF_TRUE_GOTO" select="IF_TRUE_GOTO"/>
  76. <!-- wykrycie czy goto idzie do proces_init czy do kroku procesu -->
  77. <xsl:for-each select="../../items/item[ID=$IF_TRUE_GOTO]">
  78. <xsl:element name="GOTO_NEXT_PROCES_TYPE">
  79. <xsl:value-of select="TYPE"/>
  80. </xsl:element>
  81. <xsl:element name="outgoing_name">
  82. <xsl:choose>
  83. <xsl:when test="TYPE='PROCES_INIT'">
  84. <xsl:value-of select="concat('StartEvent_',$IF_TRUE_GOTO)"/>
  85. </xsl:when>
  86. <xsl:otherwise>
  87. <xsl:value-of select="concat('Task_',$IF_TRUE_GOTO)"/>
  88. </xsl:otherwise>
  89. </xsl:choose>
  90. </xsl:element>
  91. </xsl:for-each>
  92. </xsl:element>
  93. </xsl:for-each>
  94. </xsl:variable>
  95. <xsl:choose>
  96. <xsl:when test="$outgoings/outgoing_id">
  97. <xsl:copy-of select="$outgoings/*"/>
  98. <xsl:copy-of select="$GOTO_event/*"/>
  99. </xsl:when>
  100. <xsl:otherwise>
  101. <xsl:choose>
  102. <xsl:when test="$GOTO_event/IF_TRUE_GOTO">
  103. <xsl:copy-of select="$GOTO_event/*"/>
  104. </xsl:when>
  105. <xsl:otherwise>
  106. <!-- jest koniec procesu -->
  107. <xsl:copy-of select="$outgoings/outgoing_name"/>
  108. <xsl:element name="EndEvent">
  109. <xsl:value-of select="$outgoings/outgoing_name"/>
  110. </xsl:element>
  111. <xsl:element name="TaskName">
  112. <xsl:value-of select="$outgoings/outgoing_name"/>
  113. </xsl:element>
  114. </xsl:otherwise>
  115. </xsl:choose>
  116. </xsl:otherwise>
  117. </xsl:choose>
  118. <xsl:choose>
  119. <xsl:when test="$GOTO_event/IF_TRUE_GOTO/GOTO_NEXT_PROCES_TYPE='PROCES'">
  120. <xsl:element name="outgoing_id">
  121. <xsl:value-of select="$GOTO_event/IF_TRUE_GOTO/GOTO_ID"/>
  122. </xsl:element>
  123. <xsl:element name="outgoing_name">
  124. <xsl:value-of select="concat('Task_',$GOTO_event/IF_TRUE_GOTO/GOTO_ID)"/>
  125. </xsl:element>
  126. </xsl:when>
  127. <xsl:when test="$GOTO_event/IF_TRUE_GOTO/GOTO_NEXT_PROCES_TYPE='PROCES_INIT'">
  128. <xsl:element name="outgoing_id">
  129. <xsl:value-of select="$GOTO_event/IF_TRUE_GOTO/GOTO_ID"/>
  130. </xsl:element>
  131. <xsl:element name="outgoing_name">
  132. <xsl:value-of select="concat('StartEvent_',$GOTO_event/IF_TRUE_GOTO/GOTO_ID)"/>
  133. </xsl:element>
  134. </xsl:when>
  135. </xsl:choose>
  136. </xsl:template>
  137. <xsl:template name="find_child_proces">
  138. <xsl:param name="proces_id" />
  139. <xsl:param name="count"/>
  140. <xsl:choose>
  141. <xsl:when test="$count > 0">
  142. <xsl:for-each select="/data/items/item[TYPE='PROCES' and A_STATUS!='DELETED' and PARENT_ID=$proces_id]">
  143. <xsl:sort select="concat(PARENT_ID,SORT_PRIO)"/>
  144. <!--<xsl:text>&#xa;</xsl:text>-->
  145. <xsl:element name="childs">
  146. <xsl:call-template name="detect_outgoing">
  147. <xsl:with-param name="proces_id" select="ID"/>
  148. <xsl:with-param name="parent_id" select="PARENT_ID"/>
  149. <xsl:with-param name="current_sort_prio" select="SORT_PRIO"/>
  150. <xsl:with-param name="position" select="position()"/>
  151. </xsl:call-template>
  152. <xsl:element name="DESC">
  153. <xsl:value-of select="DESC"/>
  154. </xsl:element>
  155. <xsl:element name="child">
  156. <xsl:value-of select="ID"/>
  157. </xsl:element>
  158. <xsl:element name="Task">
  159. <xsl:value-of select="concat('Task_',ID)"/>
  160. </xsl:element>
  161. <xsl:element name="TaskName">
  162. <xsl:value-of select="concat('Task_',ID)"/>
  163. </xsl:element>
  164. <xsl:element name="PARENT_ID">
  165. <xsl:value-of select="PARENT_ID"/>
  166. </xsl:element>
  167. <xsl:element name="incoming_name">
  168. <xsl:value-of select="concat('Task_',PARENT_ID)"/>
  169. </xsl:element>
  170. <xsl:element name="SORT_PRIO">
  171. <xsl:value-of select="SORT_PRIO"/>
  172. </xsl:element>
  173. <xsl:element name="current_root">
  174. <xsl:value-of select="position()"/>
  175. </xsl:element>
  176. <xsl:call-template name="Pools">
  177. <xsl:with-param name="proces_id" select="ID"/>
  178. </xsl:call-template>
  179. </xsl:element>
  180. <xsl:call-template name="find_child_proces">
  181. <xsl:with-param name="proces_id" select="ID"/>
  182. <xsl:with-param name="count" select="$count - 1"/>
  183. </xsl:call-template>
  184. </xsl:for-each>
  185. </xsl:when>
  186. <xsl:otherwise>
  187. Error in loop!!!(<xsl:value-of select="$count"/>)
  188. </xsl:otherwise>
  189. </xsl:choose>
  190. </xsl:template>
  191. </xsl:stylesheet>