开发者

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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜