开发者

how to sort xml?

开发者 https://www.devze.com 2022-12-14 05:58 出处:网络
i have an XML file that looks like this: <root> <data name=\"UserName\">User Name</data>

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

精彩评论

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