Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <param xsi:type="Bank">
- <bankData name="ABC"/>
- <branchAddress id="ABCB1">NY</branchAddress>
- <legalAddress id="ABCL1">UK</legalAddress>
- </param>
- <xsl:variable name="bankElementSeq" as="element()*">
- <bankData/><legalAddress/><branchAddress/>
- </xsl:variable>
- <xsl:template match="param/*">
- <xsl:if test="param/@xsi:type='Bank'">
- <xsl:perform-sort select="param/*">
- <xsl:sort select="index-of($bankElementSeq//node-name(.), node-name(.))"/>
- </xsl:perform-sort>
- </xsl:if>
- </xsl:template>
- <param xsi:type="Bank">
- <bankData name="ABC"/>
- <legalAddress id="ABCL1">UK</legalAddress>
- <branchAddress id="ABCB1">NY</branchAddress>
- </param>
- <param xsi:type="Bank">
- </param>
- <xsl:template match="param/*">
- <xsl:if test="param/@xsi:type='Bank'">
- <xsl:perform-sort select="param/*">
- <xsl:sort select="index-of($bankElementSeq//node-name(.), node-name(.))"/>
- </xsl:perform-sort>
- </xsl:if>
- </xsl:template>
- <xsl:template match="param[@xsi:type='Bank']">
- <xsl:perform-sort select="*">
- <xsl:sort select="index-of($bankElementSeq/node-name(.), node-name(.))"/>
- </xsl:perform-sort>
- </xsl:template>
- <?xml version="1.0" encoding="UTF-8"?>
- <xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
- <xsl:variable name="bankElementSeq" as="element()*">
- <bankData/><legalAddress/><branchAddress/>
- </xsl:variable>
- <!-- the following pattern restricts the match to exactly the type of param you want to modify -->
- <xsl:template match="param[@xsi:type='Bank']">
- <xsl:copy>
- <xsl:copy-of select="@*"/>
- <xsl:variable name="param" select="."/>
- <!-- iterate over the elements in the sorting order -->
- <xsl:for-each select="$bankElementSeq">
- <!-- and copy the found found by 'local-name' -->
- <xsl:copy-of select="$param/*[local-name() = local-name(current())]"/>
- </xsl:for-each>
- </xsl:copy>
- </xsl:template>
- </xsl:stylesheet>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement