This is my XML Structure like this
input :-
<MYDATA>
<DETAILS>
<DESCRIPTION>EASE</DESCRIPTION>
</DETAILS>
<DETAILS>
<DESCRIPTION>COMPLEX</DESCRIPTION>
</DETAILS>
<DETAILS>
<DESCRIPTION>SIMPLE</DESCRIPTION>
</DETAILS>
</MYDATA>
I want to display like this using xsl sort it mean custom sort i want to display firts simple second ease and third complex
Output :-
<MYDATA>
<DETAILS>
<DESCRIPTION>SIMPLE</DESCRIPTION>
</DETAILS>
<DETAILS>
<DESCRIPTION>EASE</DESCRIPTION>
</DETAILS>
<DETAILS>
<DESCRIPTION>COMPLEX</DESCRIPTION>
</DETAILS>
</MYDATA>
Starting from Jose's idea, here is something with less code:
There is a generic way to solve the problem. What you need is to define a variable with the sorted list you want to use. Then you use a recusive call to show the elements by that order. Basicly you go by the elements of variable "sortOrder", applying then to a apply-template call that use that value the selects the node that you need.
If you know what all the possible values you could do, you could do a series of condition-specific
apply-templates
calls:So if you know what order you want them in and the potential options aren't going to change, it will output them in whatever order your
apply-templates
rules are set.Of course, if it's more complicated than that, you might consider storing sort order on the data side and include that in your XSL so you can just sort by that.