I have the following xml snippet which appears in many many places, but the order of which the TYPE element appears are random. Also, there is no guarentee that ALL Types will be available e.g. some snippets might have Visio and/or Outlook or any other nodes missing:
<Applications>
<Type Name="Word">
<Type Name="Excel">
<Type Name="PowerPoint">
<Type Name="Visio">
<Type Name="Outlook">
</Applications>
I want to reorder the Type element so that should Type Excel exists, it will always be at the top of the list, and so on:
if EXCEL exists,
place TYPE Excel at the top.
if WORD exists,
place TYPE Word next,
.
.
.
I have tried with xsl:copy, a couple of xsl:if and then apply the specific templates, also xsl:whens. Unfortunately none of which worked for me. I had a look at another post on reordering xml node elements, and that didn't seem like what I wanted (it used xsl:call-templates, which I don't have).
I have something that started off like the following, and I'm thinking that I need to add the manipulation code above to the bottom of this:
XML Updated
<xsl:template match="Applications">
<xsl:element name="Applications">
<xsl:element name="Type">
<xsl:attribute name="Name">PowerPoint</xsl:attribute>
</xsl:element>
<xsl:element name="Type">
<xsl:attribute name="Name">Outlook</xsl:attribute>
</xsl:element>
<xsl:apply-templates>
<xsl:sort select="string-length(substring-before(';Excel;PowerPoint;Outlook;Word;Visio',@Name))"/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>
Wanted:
<Applications>
<Type Name="Excel">
<Type Name="PowerPoint">
<Type Name="Outlook">
<Type Name="Word">
<Type Name="Visio">
</Applications>
But gotten:
<Applications>
<Type Name="PowerPoint">
<Type Name="Outlook">
<Type Name="Excel">
<Type Name="Word">
<Type Name="Visio">
</Applications>
Appreciate help on getting this thing to work... TIA.