From: W. Trevor King Date: Fri, 1 Jul 2011 14:32:10 +0000 (-0400) Subject: Add Gramps-sorting example to XSLT post. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9b7d849a728e38a17f23b9b2d107fbe0266b444d;p=blog.git Add Gramps-sorting example to XSLT post. --- diff --git a/posts/XSLT.mdwn b/posts/XSLT.mdwn index 512c744..03b4731 100644 --- a/posts/XSLT.mdwn +++ b/posts/XSLT.mdwn @@ -12,10 +12,54 @@ simple [[example|chapter]] from this intro and also included a [[slightly more complicated setup|code]] for generating online help for a list of macros. +XSLT is also useful for standardizing XML content. For example, I was +recently trying to compare to [[Gramps]] XML files, to see what had +changed between two database backups. Unfortunately, the backup XML +was not sorted by `id`, so there were many diff chunks due to node +shuffling that didn't represent any useful information. With the +following XSLT: + + + + + + + + + + + + + + + + + + + + + + + +With the above saved as `sort-by-id.xsl`, you can sort `some.xml` using + + $ xsltproc --nonet --novalid sort-by-id.xsl some.xml + +You can compare two [[Gramps]] XML files with + + $ diff -u <(zcat wtk_2011-06-30b.gramps | xsltproc --nonet --novalid sort-by-id.xsl -) + <(zcat wtk_2011-06-30d.gramps | xsltproc --nonet --novalid sort-by-id.xsl -) | less + +Jesper Tverskov has a nice page about [the identity template and +related tricks][identity] if you want more examples of quasi-copy +transforms. + [XSLT]: http://www.w3.org/TR/xslt [w3]: http://www.w3schools.com/xsl/ [intro]: http://nwalsh.com/docs/tutorials/xsl/xsl/slides.html [xsltproc]: http://www.xmlsoft.org/XSLT/ +[identity]: http://www.xmlplease.com/xsltidentity [[!tag tags/tools]] [[!tag tags/web]]