xmltools icon indicating copy to clipboard operation
xmltools copied to clipboard

Add XML Sort

Open marcieldeg opened this issue 5 years ago • 1 comments
trafficstars

Please add "XML Sort" funcionality. It's very useful to compare two XML's.

Something like this tool: https://archive.codeplex.com/?p=xmlsorter

marcieldeg avatar Mar 03 '20 11:03 marcieldeg

Hi,

I'll think about adding such a method. I'm just wondering how to handle comments, cdata blocs, etc. Note that currently you can already do the same with a XSL stylesheet. For instance:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml"/>

  <xsl:template match="*">
    <xsl:element name="{name()}">
      <xsl:apply-templates select="@*">
        <xsl:sort select="name()"/>
      </xsl:apply-templates>
      <xsl:apply-templates select="*">
        <xsl:sort select="name()"/>
      </xsl:apply-templates>
    </xsl:element>
  </xsl:template>

  <xsl:template match="@*">
    <xsl:attribute name="{name()}"><xsl:value-of select="."/></xsl:attribute>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:value-of select="."/>
  </xsl:template>
</xsl:stylesheet>

Best Regards

morbac avatar Mar 03 '20 13:03 morbac