Advertisement
Guest User

XSLT

a guest
May 29th, 2013
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.96 KB | None | 0 0
  1. XML FILE:
  2. <?xml version="1.0" encoding="UTF-8"?>
  3. <comtec version="2008">
  4. <trip>
  5. <id>15ORS</id>
  6. <code>test_lje_04</code>
  7. <name>test_lje_04</name>
  8. <trip_status>planned</trip_status>
  9. <trip_group>
  10. <code>default</code>
  11. <name>default</name>
  12. </trip_group>
  13. <department>
  14. <code>osdd</code>
  15. <name>osdd</name>
  16. <division>
  17. <code>default</code>
  18. <name>default</name>
  19. </division>
  20. </department>
  21. <from_instant>2013-05-24T07:00:00+02:00</from_instant>
  22. <till_instant>2013-05-24T22:05:00+02:00</till_instant>
  23. <start_window>
  24. <from_instant>2013-05-24T06:00:00+02:00</from_instant>
  25. <till_instant>2013-05-24T07:00:00+02:00</till_instant>
  26. </start_window>
  27. <finish_window>
  28. <from_instant>2013-05-24T22:00:00+02:00</from_instant>
  29. <till_instant>2013-05-24T23:00:00+02:00</till_instant>
  30. </finish_window>
  31. <reference_start_instant>2013-05-24T06:00:00+02:00</reference_start_instant>
  32. <reference_finish_instant>2013-05-24T23:00:00+02:00</reference_finish_instant>
  33. <allowForProposalPlan>true</allowForProposalPlan>
  34. <allowForBatchPlan>true</allowForBatchPlan>
  35. <comment/>
  36. <action id="450">
  37. <action_kind>
  38. <code>travel</code>
  39. <name>travel</name>
  40. <action_spec_code>travel</action_spec_code>
  41. <action_spec_name>travel</action_spec_name>
  42. </action_kind>
  43. <addressId>99999998-TEST_NO2</addressId>
  44. <planned>
  45. <from_instant>2001-01-01T00:00:00+01:00</from_instant>
  46. <till_instant>2001-01-01T07:58:44+01:00</till_instant>
  47. <distance>503.207</distance>
  48. </planned>
  49. <expected>
  50. <from_instant>2001-01-01T00:00:00+01:00</from_instant>
  51. <till_instant>2001-01-01T07:58:44+01:00</till_instant>
  52. <distance>503.207</distance>
  53. </expected>
  54. <percentage_loaded>0</percentage_loaded>
  55. <resources>
  56. <resourceId>WT-704</resourceId>
  57. </resources>
  58. <revenue>0</revenue>
  59. </action>
  60. <action id="442">
  61. <action_kind>
  62. <code>couple</code>
  63. <name>couple</name>
  64. <action_spec_code>couple</action_spec_code>
  65. <action_spec_name>couple</action_spec_name>
  66. </action_kind>
  67. <addressId>99999998-TEST_NO2</addressId>
  68. <planned>
  69. <from_instant>2013-05-24T07:00:00+02:00</from_instant>
  70. <till_instant>2013-05-24T07:05:00+02:00</till_instant>
  71. <distance>0</distance>
  72. </planned>
  73. <expected>
  74. <from_instant>2013-05-24T07:00:00+02:00</from_instant>
  75. <till_instant>2013-05-24T07:05:00+02:00</till_instant>
  76. <distance>0</distance>
  77. </expected>
  78. <couple>
  79. <resourceId>WT-704</resourceId>
  80. </couple>
  81. <percentage_loaded>0</percentage_loaded>
  82. <resources>
  83. <resourceId>WT-704</resourceId>
  84. </resources>
  85. <revenue>0</revenue>
  86. </action>
  87. <action id="445">
  88. <action_kind>
  89. <code>coupling</code>
  90. <name>coupling</name>
  91. <action_spec_code>coupling</action_spec_code>
  92. <action_spec_name>coupling</action_spec_name>
  93. </action_kind>
  94. <addressId>99999998-TEST_NO2</addressId>
  95. <planned>
  96. <from_instant>2013-05-24T07:00:00+02:00</from_instant>
  97. <till_instant>2013-05-24T07:05:00+02:00</till_instant>
  98. <distance>0</distance>
  99. </planned>
  100. <expected>
  101. <from_instant>2013-05-24T07:00:00+02:00</from_instant>
  102. <till_instant>2013-05-24T07:05:00+02:00</till_instant>
  103. <distance>0</distance>
  104. </expected>
  105. <percentage_loaded>0</percentage_loaded>
  106. <resources>
  107. <resourceId>WT-704</resourceId>
  108. </resources>
  109. <revenue>0</revenue>
  110. </action>
  111. <action id="454">
  112. <action_kind>
  113. <code>travel</code>
  114. <name>travel</name>
  115. <action_spec_code>travel</action_spec_code>
  116. <action_spec_name>travel</action_spec_name>
  117. </action_kind>
  118. <addressId>99999998-TESTORTE02</addressId>
  119. <planned>
  120. <from_instant>2013-05-24T07:05:00+02:00</from_instant>
  121. <till_instant>2013-05-24T08:22:39+02:00</till_instant>
  122. <distance>86.879</distance>
  123. </planned>
  124. <expected>
  125. <from_instant>2013-05-24T07:05:00+02:00</from_instant>
  126. <till_instant>2013-05-24T08:22:39+02:00</till_instant>
  127. <distance>86.879</distance>
  128. </expected>
  129. <percentage_loaded>0</percentage_loaded>
  130. <resources>
  131. <resourceId>WT-704</resourceId>
  132. </resources>
  133. <revenue>0</revenue>
  134. </action>
  135. <action id="453">
  136. <action_kind>
  137. <code>stop</code>
  138. <name>stop</name>
  139. <action_spec_code>stop</action_spec_code>
  140. <action_spec_name>stop</action_spec_name>
  141. </action_kind>
  142. <addressId>99999998-TESTORTE02</addressId>
  143. <planned>
  144. <from_instant>2013-05-24T08:22:39+02:00</from_instant>
  145. <till_instant>2013-05-24T11:01:00+02:00</till_instant>
  146. <distance>0</distance>
  147. </planned>
  148. <expected>
  149. <from_instant>2013-05-24T08:22:39+02:00</from_instant>
  150. <till_instant>2013-05-24T11:01:00+02:00</till_instant>
  151. <distance>0</distance>
  152. </expected>
  153. <load>
  154. <orderId>0000211000001460000100001</orderId>
  155. </load>
  156. <percentage_loaded>9</percentage_loaded>
  157. <stop_number>1</stop_number>
  158. <resources>
  159. <resourceId>WT-704</resourceId>
  160. </resources>
  161. <revenue>0</revenue>
  162. </action>
  163. <action id="456">
  164. <action_kind>
  165. <code>wait_task_available</code>
  166. <name>wait_task_available</name>
  167. <action_spec_code>wait_task_available</action_spec_code>
  168. <action_spec_name>wait_task_available</action_spec_name>
  169. </action_kind>
  170. <addressId>99999998-TESTORTE02</addressId>
  171. <planned>
  172. <from_instant>2013-05-24T08:22:39+02:00</from_instant>
  173. <till_instant>2013-05-24T11:00:00+02:00</till_instant>
  174. <distance>0</distance>
  175. </planned>
  176. <expected>
  177. <from_instant>2013-05-24T08:22:39+02:00</from_instant>
  178. <till_instant>2013-05-24T11:00:00+02:00</till_instant>
  179. <distance>0</distance>
  180. </expected>
  181. <percentage_loaded>0</percentage_loaded>
  182. <resources>
  183. <resourceId>WT-704</resourceId>
  184. </resources>
  185. <revenue>0</revenue>
  186. </action>
  187. <action id="436">
  188. <action_kind>
  189. <code>pickup</code>
  190. <name>pickup</name>
  191. <action_spec_code>pickup</action_spec_code>
  192. <action_spec_name>Pickup</action_spec_name>
  193. </action_kind>
  194. <addressId>99999998-TESTORTE02</addressId>
  195. <planned>
  196. <from_instant>2013-05-24T11:00:00+02:00</from_instant>
  197. <till_instant>2013-05-24T11:01:00+02:00</till_instant>
  198. <distance>0</distance>
  199. </planned>
  200. <expected>
  201. <from_instant>2013-05-24T11:00:00+02:00</from_instant>
  202. <till_instant>2013-05-24T11:01:00+02:00</till_instant>
  203. <distance>0</distance>
  204. </expected>
  205. <pickup>
  206. <orderId>0000211000001460000100001</orderId>
  207. <taskId>114ORTK</taskId>
  208. <order_info>
  209. <transports>
  210. <transport>
  211. <pickup_taskId>114ORTK</pickup_taskId>
  212. <deliver_taskId>113ORTK</deliver_taskId>
  213. <pickup_addressId>99999998-TESTORTE02</pickup_addressId>
  214. <delivery_addressId>3-ONTIOSLO21</delivery_addressId>
  215. <route_part>main</route_part>
  216. <department>
  217. <code>default</code>
  218. <name>default</name>
  219. <division>
  220. <code>default</code>
  221. <name>default</name>
  222. </division>
  223. </department>
  224. </transport>
  225. </transports>
  226. </order_info>
  227. </pickup>
  228. <load>
  229. <orderId>0000211000001460000100001</orderId>
  230. </load>
  231. <percentage_loaded>9</percentage_loaded>
  232. <stop_number>1</stop_number>
  233. <resources>
  234. <resourceId>WT-704</resourceId>
  235. </resources>
  236. <revenue>0</revenue>
  237. </action>
  238. <action id="458">
  239. <action_kind>
  240. <code>travel</code>
  241. <name>travel</name>
  242. <action_spec_code>travel</action_spec_code>
  243. <action_spec_name>travel</action_spec_name>
  244. </action_kind>
  245. <addressId>3-ONTIOSLO21</addressId>
  246. <planned>
  247. <from_instant>2013-05-24T11:01:00+02:00</from_instant>
  248. <till_instant>2013-05-24T12:00:26+02:00</till_instant>
  249. <distance>63.643</distance>
  250. </planned>
  251. <expected>
  252. <from_instant>2013-05-24T11:01:00+02:00</from_instant>
  253. <till_instant>2013-05-24T12:00:26+02:00</till_instant>
  254. <distance>63.643</distance>
  255. </expected>
  256. <percentage_loaded>9</percentage_loaded>
  257. <resources>
  258. <resourceId>WT-704</resourceId>
  259. </resources>
  260. <revenue>0</revenue>
  261. </action>
  262. <action id="457">
  263. <action_kind>
  264. <code>stop</code>
  265. <name>stop</name>
  266. <action_spec_code>stop</action_spec_code>
  267. <action_spec_name>stop</action_spec_name>
  268. </action_kind>
  269. <addressId>3-ONTIOSLO21</addressId>
  270. <planned>
  271. <from_instant>2013-05-24T12:00:26+02:00</from_instant>
  272. <till_instant>2013-05-24T12:01:26+02:00</till_instant>
  273. <distance>0</distance>
  274. </planned>
  275. <expected>
  276. <from_instant>2013-05-24T12:00:26+02:00</from_instant>
  277. <till_instant>2013-05-24T12:01:26+02:00</till_instant>
  278. <distance>0</distance>
  279. </expected>
  280. <percentage_loaded>0</percentage_loaded>
  281. <stop_number>2</stop_number>
  282. <resources>
  283. <resourceId>WT-704</resourceId>
  284. </resources>
  285. <revenue>0</revenue>
  286. </action>
  287. <action id="437">
  288. <action_kind>
  289. <code>deliver</code>
  290. <name>deliver</name>
  291. <action_spec_code>deliver</action_spec_code>
  292. <action_spec_name>Deliver</action_spec_name>
  293. </action_kind>
  294. <addressId>3-ONTIOSLO21</addressId>
  295. <planned>
  296. <from_instant>2013-05-24T12:00:26+02:00</from_instant>
  297. <till_instant>2013-05-24T12:01:26+02:00</till_instant>
  298. <distance>0</distance>
  299. </planned>
  300. <expected>
  301. <from_instant>2013-05-24T12:00:26+02:00</from_instant>
  302. <till_instant>2013-05-24T12:01:26+02:00</till_instant>
  303. <distance>0</distance>
  304. </expected>
  305. <delivery>
  306. <orderId>0000211000001460000100001</orderId>
  307. <taskId>113ORTK</taskId>
  308. <order_info>
  309. <transports>
  310. <transport>
  311. <pickup_taskId>114ORTK</pickup_taskId>
  312. <deliver_taskId>113ORTK</deliver_taskId>
  313. <pickup_addressId>99999998-TESTORTE02</pickup_addressId>
  314. <delivery_addressId>3-ONTIOSLO21</delivery_addressId>
  315. <route_part>main</route_part>
  316. <department>
  317. <code>default</code>
  318. <name>default</name>
  319. <division>
  320. <code>default</code>
  321. <name>default</name>
  322. </division>
  323. </department>
  324. </transport>
  325. </transports>
  326. </order_info>
  327. </delivery>
  328. <percentage_loaded>0</percentage_loaded>
  329. <stop_number>2</stop_number>
  330. <resources>
  331. <resourceId>WT-704</resourceId>
  332. </resources>
  333. <revenue>0</revenue>
  334. </action>
  335. <action id="455">
  336. <action_kind>
  337. <code>travel</code>
  338. <name>travel</name>
  339. <action_spec_code>travel</action_spec_code>
  340. <action_spec_name>travel</action_spec_name>
  341. </action_kind>
  342. <addressId>99999998-TEST_NO2</addressId>
  343. <planned>
  344. <from_instant>2013-05-24T12:01:26+02:00</from_instant>
  345. <till_instant>2013-05-24T12:31:53+02:00</till_instant>
  346. <distance>26.547</distance>
  347. </planned>
  348. <expected>
  349. <from_instant>2013-05-24T12:01:26+02:00</from_instant>
  350. <till_instant>2013-05-24T12:31:53+02:00</till_instant>
  351. <distance>26.547</distance>
  352. </expected>
  353. <percentage_loaded>0</percentage_loaded>
  354. <resources>
  355. <resourceId>WT-704</resourceId>
  356. </resources>
  357. <revenue>0</revenue>
  358. </action>
  359. <action id="452">
  360. <action_kind>
  361. <code>wait_action</code>
  362. <name>wait_action</name>
  363. <action_spec_code>wait_action</action_spec_code>
  364. <action_spec_name>wait_action</action_spec_name>
  365. </action_kind>
  366. <addressId>99999998-TEST_NO2</addressId>
  367. <planned>
  368. <from_instant>2013-05-24T12:31:53+02:00</from_instant>
  369. <till_instant>2013-05-24T22:00:00+02:00</till_instant>
  370. <distance>0</distance>
  371. </planned>
  372. <expected>
  373. <from_instant>2013-05-24T12:31:53+02:00</from_instant>
  374. <till_instant>2013-05-24T22:00:00+02:00</till_instant>
  375. <distance>0</distance>
  376. </expected>
  377. <percentage_loaded>0</percentage_loaded>
  378. <resources>
  379. <resourceId>WT-704</resourceId>
  380. </resources>
  381. <revenue>0</revenue>
  382. </action>
  383. <action id="443">
  384. <action_kind>
  385. <code>decouple</code>
  386. <name>decouple</name>
  387. <action_spec_code>decouple</action_spec_code>
  388. <action_spec_name>decouple</action_spec_name>
  389. </action_kind>
  390. <addressId>99999998-TEST_NO2</addressId>
  391. <planned>
  392. <from_instant>2013-05-24T22:00:00+02:00</from_instant>
  393. <till_instant>2013-05-24T22:05:00+02:00</till_instant>
  394. <distance>0</distance>
  395. </planned>
  396. <expected>
  397. <from_instant>2013-05-24T22:00:00+02:00</from_instant>
  398. <till_instant>2013-05-24T22:05:00+02:00</till_instant>
  399. <distance>0</distance>
  400. </expected>
  401. <decouple>
  402. <resourceId>WT-704</resourceId>
  403. </decouple>
  404. <percentage_loaded>0</percentage_loaded>
  405. <resources>
  406. <resourceId>WT-704</resourceId>
  407. </resources>
  408. <revenue>0</revenue>
  409. </action>
  410. <action id="446">
  411. <action_kind>
  412. <code>decoupling</code>
  413. <name>decoupling</name>
  414. <action_spec_code>decoupling</action_spec_code>
  415. <action_spec_name>decoupling</action_spec_name>
  416. </action_kind>
  417. <addressId>99999998-TEST_NO2</addressId>
  418. <planned>
  419. <from_instant>2013-05-24T22:00:00+02:00</from_instant>
  420. <till_instant>2013-05-24T22:05:00+02:00</till_instant>
  421. <distance>0</distance>
  422. </planned>
  423. <expected>
  424. <from_instant>2013-05-24T22:00:00+02:00</from_instant>
  425. <till_instant>2013-05-24T22:05:00+02:00</till_instant>
  426. <distance>0</distance>
  427. </expected>
  428. <percentage_loaded>0</percentage_loaded>
  429. <resources>
  430. <resourceId>WT-704</resourceId>
  431. </resources>
  432. <revenue>0</revenue>
  433. </action>
  434. </trip>
  435. </comtec>
  436.  
  437. XSLT FILE:
  438. <?xml version="1.0" encoding="UTF-8"?>
  439. <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns="http://www.kewill.com/logistics/klic/trip-plan" exclude-result-prefixes="fn xs">
  440. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  441.  
  442. <!-- Code conversion through eu1102 -->
  443. <xsl:include href="cwksbCodeConversion.xsl"/>
  444. <xsl:variable name="ol.custProspectCodeConversionFile">cwklic_codeMappings.xml</xsl:variable>
  445.  
  446. <!-- Needed for translation of action codes from OTD to KL codes -->
  447. <xsl:key name="actionCode" match="actionCode" use="@actionCodeFrom"/>
  448.  
  449. <xsl:param name="actionCode-map">
  450. <actionCode actionCodeFrom="couple" actionCodeTo="1"/>
  451. <actionCode actionCodeFrom="stop" actionCodeTo="5"/>
  452. <actionCode actionCodeFrom="decouple" actionCodeTo="2"/>
  453. <actionCode actionCodeFrom="pickup" actionCodeTo="3"/>
  454. <actionCode actionCodeFrom="deliver" actionCodeTo="4"/>
  455. </xsl:param>
  456.  
  457. <xsl:template match="/comtec">
  458. <trip-plan type="tag">
  459. <ediCustomerNumber>99999996</ediCustomerNumber>
  460. <ediCustomerDepartment><xsl:value-of select="trip/department/code"/></ediCustomerDepartment>
  461. <ediParm1>4</ediParm1>
  462. <ediParm2>O</ediParm2>
  463. <ediParm3>T</ediParm3>
  464. <!--transmitter></transmitter-->
  465. <!--receiver></receiver-->
  466. <ediReference><xsl:value-of select="trip/id"/></ediReference>
  467. <!--referenceIndication></referenceIndication-->
  468. <!--internalShipmentNumber></internalShipmentNumber-->
  469. <ediFunction1>95</ediFunction1>
  470. <!--
  471. What does ediCustomerSearchName do?
  472. -->
  473. <!--ediCustomerSearchName>TODO - how to manage updates?</ediCustomerSearchName-->
  474. <!--reason></reason-->
  475. <!--employeesInitials></employeesInitials-->
  476.  
  477. <xsl:apply-templates select="trip" />
  478. </trip-plan>
  479. </xsl:template>
  480.  
  481. <xsl:template match="trip">
  482. <trip type="tag">
  483. <loadingDate><xsl:value-of select="substring(from_instant,1,10)"/></loadingDate>
  484. <loadingTime><xsl:value-of select="concat(substring(from_instant,12,5), ':00')"/></loadingTime>
  485. <unloadingDate><xsl:value-of select="substring(till_instant,1,10)"/></unloadingDate>
  486. <unloadingTime><xsl:value-of select="concat(substring(till_instant,12,5), ':00')"/></unloadingTime>
  487. <primaryReference><xsl:value-of select="code"/></primaryReference>
  488.  
  489. <xsl:if test="comment !=''">
  490. <fileReferences type="tag">
  491. <referenceCode>OTD</referenceCode>
  492. <referenceText><xsl:value-of select="comment"/></referenceText>
  493. </fileReferences>
  494. </xsl:if>
  495.  
  496. <xsl:for-each-group select="action" group-starting-with="action[action_kind/code = 'travel']">
  497. <xsl:variable name="travel-head" select="."/>
  498. <!--
  499. <test><xsl:value-of select="current-group()[self::action[action_kind/code = $actionCode-map/actionCode/@actionCodeFrom]]" /></test>
  500. <test2><xsl:value-of select="current-group()" /></test2>
  501. -->
  502. <xsl:apply-templates select="current-group()[self::action[action_kind/code = $actionCode-map/actionCode/@actionCodeFrom]]">
  503. <xsl:with-param name="travel" select="$travel-head"/>
  504. </xsl:apply-templates>
  505. </xsl:for-each-group>
  506. </trip>
  507. </xsl:template>
  508.  
  509. <xsl:template match="action">
  510. <xsl:param name="travel"/>
  511. <xsl:copy>
  512. <code>
  513. <xsl:value-of select="key('actionCode', action_kind/code, $actionCode-map)/@actionCodeTo"/>
  514. </code>
  515. <value>
  516. <xsl:value-of
  517. select="if (not(exists((current-group() except $travel)
  518. [current() >> . and action_kind/code = $actionCode-map/actionCode/@actionCodeFrom])))
  519. then $travel/planned/distance else 0"/>
  520. </value>
  521. </xsl:copy>
  522. </xsl:template>
  523.  
  524. <xsl:template name="createAddress">
  525. <xsl:param name="myAddressId" />
  526. <xsl:param name="myTypeOfAddress" />
  527.  
  528. <address>
  529. <relationNumber><xsl:value-of select="substring-before($myAddressId,'-')"/></relationNumber>
  530. <typeOfAddress>
  531. <xsl:choose>
  532. <xsl:when test="$myTypeOfAddress = 'pickup'">
  533. <xsl:text>1</xsl:text>
  534. </xsl:when>
  535. <xsl:when test="$myTypeOfAddress = 'deliver'">
  536. <xsl:text>2</xsl:text>
  537. </xsl:when>
  538. <xsl:when test="$myTypeOfAddress = 'couple'"><!--pickup=loading e.g. -->
  539. <xsl:text>TODOFOR types like couple</xsl:text>
  540. </xsl:when>
  541. <xsl:when test="$myTypeOfAddress = 'coupling'"><!--pickup=loading e.g. -->
  542. <xsl:text>TODOFOR types like coupling</xsl:text>
  543. </xsl:when>
  544. <xsl:when test="$myTypeOfAddress = 'stop'"><!--pickup=loading e.g. -->
  545. <xsl:text>TODOFOR types like stop</xsl:text>
  546. </xsl:when>
  547. <xsl:when test="$myTypeOfAddress = 'travel'"><!--pickup=loading e.g. -->
  548. <xsl:text>TODOFOR types like travel</xsl:text>
  549. </xsl:when>
  550. <xsl:otherwise>
  551. <xsl:value-of select="$myTypeOfAddress" />
  552. </xsl:otherwise>
  553. </xsl:choose>
  554. </typeOfAddress>
  555. <searchName><xsl:value-of select="substring-after($myAddressId,'-')"/></searchName>
  556. </address>
  557. </xsl:template>
  558.  
  559. <xsl:template name="createLeg">
  560. <xsl:param name="myActionKindCode" />
  561.  
  562. <xsl:if test="$myActionKindCode = 'pickup' or $myActionKindCode = 'deliver'">
  563. <leg type="tag">
  564. <legReference>
  565. <xsl:choose>
  566. <xsl:when test="$myActionKindCode = 'pickup'">
  567. <xsl:value-of select="pickup/orderId"/>
  568. </xsl:when>
  569. <xsl:when test="$myActionKindCode = 'deliver'">
  570. <xsl:value-of select="delivery/orderId"/>
  571. </xsl:when>
  572. </xsl:choose>
  573. </legReference>
  574. </leg>
  575. </xsl:if>
  576. </xsl:template>
  577. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement