Sorting based on existing elements in xslt
- by Teelo
Hi ,
I want to sort in xslt based on existing set of pattern .
Let me explain with the code:
<Types>
<Type>
<Names>
<Name>Ryan</Name>
</Names>
<Address>2344</Address>
</Type>
<Type>
<Names>
</Name>Timber</Name>
</Names>
<Address>1234</Address>
</Type>
<Type>
<Names>
</Name>Bryan</Name>
</Names>
<Address>34</Address>
</Type>
</Types>
Right now I m just calling it and getting it like (all hyperlinks)
Ryan
Timber
Bryan
Now I don't want sorting on name but I have existing pattern how I want it to get displayed.Like
Timber
Bryan
Ryan
(Also I don't want to lose the url attached to my names earlier while doing this)
I was thinking of putting earlier value in some array and sort based on the other array where I will store my existing pattern. But I am not sure how to achieve that..
My xslt looks like this now(there can be duplicate names also)
<xsl:for-each select="/Types/Type/Names/Name/text()[generate-id()=generate-id(key('Name',.)[1])]">
<xsl:call-template name="typename">
</xsl:call-template>
</xsl:for-each>
<xsl:template name="typename">
<li>
<a href="somelogicforurl"> <xsl:value-of select="."/> </a>
</li>
</xsl:template>
I am using xsl 1.0