Skip to content

Instantly share code, notes, and snippets.

@troelskn
Created May 30, 2022 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save troelskn/db169d70cdd5f1582fd0406c944bd865 to your computer and use it in GitHub Desktop.
Save troelskn/db169d70cdd5f1582fd0406c944bd865 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'nokogiri'
document = Nokogiri::XML.parse(STDIN.read) { |c| c.noent.nonet.strict }
xsl =<<XSL
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
XSL
xslt = Nokogiri::XSLT(xsl)
xml = xslt.transform(document).to_xml(indent: 2)
puts Nokogiri::XML.parse(xml) { |c| c.noent.nonet.strict }.canonicalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment