how to sort xml?
i have an XML file that looks like this:
<root>
<data name="UserName">User Name</data>
<data name="Password"&开发者_开发知识库gt;Password</data>
<data name="LogIn">Log In</data>
<data name="InvalidPassword">Invalid password</data>
<data name="InvalidUserName">Invalid username</data>
</root>
how do i sort the file itself? i want to sort by 'name'.
Here is an XSLT template that would do the trick:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:template match="/">
<root>
<xsl:apply-templates select="root/data">
<xsl:sort select="@name" order="ascending"/>
</xsl:apply-templates>
</root>
</xsl:template>
<xsl:template match="data">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
精彩评论