Advertisement
Guest User

XSLT 1

a guest
Jan 16th, 2015
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  3. <xsl:output method="xml" indent="yes" />
  4. <xsl:strip-space elements="*" />
  5. <!-- set ORDER to key of each element -->
  6. <xsl:key name="master_version" match="master_version" use="ORDER" />
  7. <xsl:key name="press_section" match="press_section" use="ORDER" />
  8. <xsl:key name="post_press_version" match="post_press_version" use="ORDER" />
  9. <xsl:key name="version" match="version" use="ORDER" />
  10. <xsl:key name="task_info_press_section" match="task_info_press_section" use="ORDER" />
  11. <xsl:key name="task_info_post_press" match="task_info_post_press" use="ORDER" />
  12. <!-- remove specified nodes -->
  13. <xsl:template match="ORDER" />
  14. <xsl:template match="ORDERPK" />
  15. <xsl:template match="PPVPK" />
  16. <xsl:template match="PRESS_x0020_SECTION" />
  17. <xsl:template match="POST_x0020_PRESS" />
  18. <!-- set attributes -->
  19. <xsl:template match="job_id | site_code | replace | Replace" />
  20. <xsl:template match="confirmed | maintenance | provisional" />
  21. <xsl:template match="confirmed | maintenance | provisional" />
  22. <!-- identity transform -->
  23. <xsl:template match="@*|node()">
  24. <xsl:copy>
  25. <xsl:apply-templates select="@*|node()" />
  26. </xsl:copy>
  27. </xsl:template>
  28. <!-- rename "dataroot" to "orders" and add attributes -->
  29. <xsl:template match="dataroot">
  30. <orders xmlns:od="urn:schemas-microsoft-com:officedata" xmlns:tg="http://www.technique- group.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.technique-group.com/schemas TGScheduleImport_v1.4.xsd" tg:version="1.2">
  31. <xsl:apply-templates />
  32. </orders>
  33. </xsl:template>
  34. <!-- nest elements and add attributes -->
  35. <xsl:template match="order">
  36. <order job_id="{job_id}" site_code="{site_code}" replace="{Replace}">
  37. <xsl:apply-templates select="@*|node()" />
  38. <xsl:apply-templates select="key('master_version', ORDERPK)" />
  39. <xsl:apply-templates select="key('press_section', ORDERPK)" />
  40. <xsl:apply-templates select="key('post_press_version', ORDERPK)" />
  41. </order>
  42. </xsl:template>
  43. <xsl:template match="press_section">
  44. <press_section>
  45. <xsl:apply-templates select="node()" />
  46. <version>
  47. <xsl:apply-templates select="key('version', ORDER)/node()" />
  48. <xsl:apply-templates select="key('task_info_press_section', ORDER)[task_seq_id = current()/sequence_id]" />
  49. </version>
  50. </press_section>
  51. </xsl:template>
  52. <xsl:template match="post_press_version">
  53. <post_press_version>
  54. <xsl:apply-templates select="node()" />
  55. <xsl:apply-templates select="key('task_info_post_press', ORDER)[POST_x0020_PRESS = current()/PPVPK]" />
  56. </post_press_version>
  57. </xsl:template>
  58. <xsl:template match="task_info_press_section">
  59. <task_info confirmed="{confirmed}" maintenance="{maintenance}" provisional="{provisional}">
  60. <xsl:apply-templates select="node()" />
  61. </task_info>
  62. </xsl:template>
  63. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement