Andrew Dunstan was kind enough to share an XML pretty printer function
for PostgreSQL, and it sure is handy when you're debugging things like
in-database unapi and MARCXML.
Note that it expects honest-to-goodness XML data type input, so for
biblio.record_entry.marc columns you'll need to cast it from TEXT.
Signed-off-by: Dan Scott <dan@coffeecode.net>
Signed-off-by: Michael Peters <mrpeters@library.in.gov>
-- Provide a named type for patching functions
CREATE TYPE evergreen.patch AS (patch TEXT);
+CREATE OR REPLACE FUNCTION evergreen.xml_pretty_print(input XML)
+ RETURNS XML
+ LANGUAGE SQL AS
+$func$
+SELECT xslt_process($1::text,
+$$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+ <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
+ <xsl:strip-space elements="*"/>
+ <xsl:template match="@*|node()">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+ </xsl:stylesheet>
+$$::text)::XML
+$func$;
+
+COMMENT ON FUNCTION evergreen.xml_pretty_print(input XML) IS
+'Simple pretty printer for XML, as written by Andrew Dunstan at http://goo.gl/zBHIk';
+
COMMIT;
--- /dev/null
+CREATE OR REPLACE FUNCTION evergreen.xml_pretty_print(input XML)
+ RETURNS XML
+ LANGUAGE SQL AS
+$func$
+SELECT xslt_process($1::text,
+$$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="1.0">
+ <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
+ <xsl:strip-space elements="*"/>
+ <xsl:template match="@*|node()">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|node()"/>
+ </xsl:copy>
+ </xsl:template>
+ </xsl:stylesheet>
+$$::text)::XML
+$func$;
+
+COMMENT ON FUNCTION evergreen.xml_pretty_print(input XML) IS
+'Simple pretty printer for XML, as written by Andrew Dunstan at http://goo.gl/zBHIk';
+