Add an XML pretty printer database function
authorDan Scott <dan@coffeecode.net>
Sat, 17 Mar 2012 01:49:45 +0000 (21:49 -0400)
committerDan Scott <dscott@laurentian.ca>
Mon, 30 Jul 2012 14:22:06 +0000 (10:22 -0400)
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>

Open-ILS/src/sql/Pg/000.functions.general.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.xml_pretty_print.sql [new file with mode: 0644]

index 6a46d1b..ffbc629 100644 (file)
@@ -36,4 +36,25 @@ $$ LANGUAGE PLPERLU STRICT IMMUTABLE;
 -- 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;
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.function.xml_pretty_print.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.function.xml_pretty_print.sql
new file mode 100644 (file)
index 0000000..0992821
--- /dev/null
@@ -0,0 +1,21 @@
+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';
+