#!/bin/bash

xslt='
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">

  <xsl:output indent="yes"/>

  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match="*[*]">
    <xsl:copy>
      <xsl:apply-templates select="@*"/>
      <xsl:apply-templates select="*">
        <xsl:sort select="local-name()"/>
      </xsl:apply-templates>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
'
echo $xslt > /tmp/sort.xslt
vimdiff <(xsltproc /tmp/sort.xslt $1 | xmllint --c14n - | xmllint --pretty 2 -) <(xsltproc /tmp/sort.xslt $2 | xmllint --c14n - | xmllint --pretty 2 -) 
rm /tmp/sort.xslt
