Ani

Ani

  • 169
  • 11.2k
  • 35.3k

sorting and sequencing in xslt transformation

Jan 4 2021 5:03 AM
Hi,
I have a service response like below xml and applying xslt, it is returning same first result details for all iterations. I have to sort the results based on sequenceNumber. Please help me.
Response XML
<resultsList>
<Accountdata>
<sequenceNumber>1</sequenceNumber>
<name>abc</name>
<country>usa</country>
</Accountdata>
<Accountdata>
<sequenceNumber>2</sequenceNumber>
<name>def</name>
<country>usa</country>
</Accountdata>
<Accountdata>
<sequenceNumber>3</sequenceNumber>
<name>ghi</name>
<country></country>
</Accountdata>
<Accountdata>
<sequenceNumber>4</sequenceNumber>
<name>xyz</name>
<country>france</country>
</Accountdata>
</resultsList>
transform xslt
<resultsList>
<xsl:for-each select="//resultsList/Accountdata">
<xsl:sort select="//resultsList/Accountdata/sequenceNumber" order="ascending"/>
<Accountdata>
<sequenceNumber>
<xsl:value-of select="//resultsList/Accountdata/sequenceNumber" />
</sequenceNumber>
<name>
<xsl:value-of select="resultsList/Accountdata/name" />
</name>
<country>
<xsl:value-of select="resultsList/Accountdata/country" />
</country>
</Accountdata>
</xsl:for-each>
</resultsList>
After transformation results xml
<resultsList>
<Accountdata>
<sequenceNumber>1</sequenceNumber>
<name>abc</name>
<country>usa</country>
</Accountdata>
<Accountdata>
<sequenceNumber>1</sequenceNumber>
<name>abc</name>
<country>usa</country>
</Accountdata>
<Accountdata>
<sequenceNumber>1</sequenceNumber>
<name>abc</name>
<country>usa</country>
</Accountdata>
<Accountdata>
<sequenceNumber>1</sequenceNumber>
<name>abc</name>
<country>usa</country>
</Accountdata>
</resultsList>

Answers (1)