Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. <param xsi:type="Bank">
  2. <bankData name="ABC"/>
  3. <branchAddress id="ABCB1">NY</branchAddress>
  4. <legalAddress id="ABCL1">UK</legalAddress>
  5. </param>
  6.  
  7. <xsl:variable name="bankElementSeq" as="element()*">
  8. <bankData/><legalAddress/><branchAddress/>
  9. </xsl:variable>
  10. <xsl:template match="param/*">
  11. <xsl:if test="param/@xsi:type='Bank'">
  12. <xsl:perform-sort select="param/*">
  13. <xsl:sort select="index-of($bankElementSeq//node-name(.), node-name(.))"/>
  14. </xsl:perform-sort>
  15. </xsl:if>
  16. </xsl:template>
  17.  
  18. <param xsi:type="Bank">
  19. <bankData name="ABC"/>
  20. <legalAddress id="ABCL1">UK</legalAddress>
  21. <branchAddress id="ABCB1">NY</branchAddress>
  22. </param>
  23.  
  24. <param xsi:type="Bank">
  25. </param>
  26.  
  27. <xsl:template match="param/*">
  28. <xsl:if test="param/@xsi:type='Bank'">
  29. <xsl:perform-sort select="param/*">
  30. <xsl:sort select="index-of($bankElementSeq//node-name(.), node-name(.))"/>
  31. </xsl:perform-sort>
  32. </xsl:if>
  33. </xsl:template>
  34.  
  35. <xsl:template match="param[@xsi:type='Bank']">
  36. <xsl:perform-sort select="*">
  37. <xsl:sort select="index-of($bankElementSeq/node-name(.), node-name(.))"/>
  38. </xsl:perform-sort>
  39. </xsl:template>
  40.  
  41. <?xml version="1.0" encoding="UTF-8"?>
  42. <xsl:stylesheet
  43. version="1.0"
  44. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  45. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  46. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
  47.  
  48. <xsl:variable name="bankElementSeq" as="element()*">
  49. <bankData/><legalAddress/><branchAddress/>
  50. </xsl:variable>
  51.  
  52. <!-- the following pattern restricts the match to exactly the type of param you want to modify -->
  53. <xsl:template match="param[@xsi:type='Bank']">
  54.  
  55. <xsl:copy>
  56. <xsl:copy-of select="@*"/>
  57. <xsl:variable name="param" select="."/>
  58.  
  59. <!-- iterate over the elements in the sorting order -->
  60. <xsl:for-each select="$bankElementSeq">
  61. <!-- and copy the found found by 'local-name' -->
  62. <xsl:copy-of select="$param/*[local-name() = local-name(current())]"/>
  63. </xsl:for-each>
  64.  
  65. </xsl:copy>
  66. </xsl:template>
  67.  
  68. </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement