|
| 1 | +-- |
| 2 | +-- first, define the functions. Turn off echoing so that expected file |
| 3 | +-- does not depend on contents of pgxml.sql. |
| 4 | +-- |
| 5 | +SET client_min_messages = warning; |
| 6 | +\set ECHO none |
| 7 | +RESET client_min_messages; |
| 8 | +select query_to_xml('select 1 as x',true,false,''); |
| 9 | + query_to_xml |
| 10 | +--------------------------------------------------------------- |
| 11 | + <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+ |
| 12 | + + |
| 13 | + <row> + |
| 14 | + <x>1</x> + |
| 15 | + </row> + |
| 16 | + + |
| 17 | + </table> + |
| 18 | + |
| 19 | +(1 row) |
| 20 | + |
| 21 | +select xslt_process( query_to_xml('select x from generate_series(1,5) as |
| 22 | +x',true,false,'')::text, |
| 23 | +$$<xsl:stylesheet version="1.0" |
| 24 | + xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 25 | +<xsl:output method="xml" indent="yes" /> |
| 26 | +<xsl:template match="*"> |
| 27 | + <xsl:copy> |
| 28 | + <xsl:copy-of select="@*" /> |
| 29 | + <xsl:apply-templates /> |
| 30 | + </xsl:copy> |
| 31 | +</xsl:template> |
| 32 | +<xsl:template match="comment()|processing-instruction()"> |
| 33 | + <xsl:copy /> |
| 34 | +</xsl:template> |
| 35 | +</xsl:stylesheet> |
| 36 | +$$::text); |
| 37 | + xslt_process |
| 38 | +--------------------------------------------------------------- |
| 39 | + <?xml version="1.0"?> + |
| 40 | + <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+ |
| 41 | + + |
| 42 | + <row> + |
| 43 | + <x>1</x> + |
| 44 | + </row> + |
| 45 | + + |
| 46 | + <row> + |
| 47 | + <x>2</x> + |
| 48 | + </row> + |
| 49 | + + |
| 50 | + <row> + |
| 51 | + <x>3</x> + |
| 52 | + </row> + |
| 53 | + + |
| 54 | + <row> + |
| 55 | + <x>4</x> + |
| 56 | + </row> + |
| 57 | + + |
| 58 | + <row> + |
| 59 | + <x>5</x> + |
| 60 | + </row> + |
| 61 | + + |
| 62 | + </table> + |
| 63 | + |
| 64 | +(1 row) |
| 65 | + |
| 66 | +CREATE TABLE xpath_test (id integer NOT NULL, t xml); |
| 67 | +INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>'); |
| 68 | +SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true') |
| 69 | +as t(id int4); |
| 70 | + id |
| 71 | +---- |
| 72 | +(0 rows) |
| 73 | + |
| 74 | +SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true') |
| 75 | +as t(id int4, doc int4); |
| 76 | + id | doc |
| 77 | +----+----- |
| 78 | + 1 | 1 |
| 79 | +(1 row) |
| 80 | + |
| 81 | +DROP TABLE xpath_test; |
| 82 | +CREATE TABLE xpath_test (id integer NOT NULL, t text); |
| 83 | +INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>'); |
| 84 | +SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true') |
| 85 | +as t(id int4); |
| 86 | + id |
| 87 | +---- |
| 88 | +(0 rows) |
| 89 | + |
| 90 | +SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true') |
| 91 | +as t(id int4, doc int4); |
| 92 | + id | doc |
| 93 | +----+----- |
| 94 | + 1 | 1 |
| 95 | +(1 row) |
| 96 | + |
| 97 | +create table articles (article_id integer, article_xml xml, date_entered date); |
| 98 | +insert into articles (article_id, article_xml, date_entered) |
| 99 | +values (2, '<article><author>test</author><pages>37</pages></article>', now()); |
| 100 | +SELECT * FROM |
| 101 | +xpath_table('article_id', |
| 102 | + 'article_xml', |
| 103 | + 'articles', |
| 104 | + '/article/author|/article/pages|/article/title', |
| 105 | + 'date_entered > ''2003-01-01'' ') |
| 106 | +AS t(article_id integer, author text, page_count integer, title text); |
| 107 | + article_id | author | page_count | title |
| 108 | +------------+--------+------------+------- |
| 109 | + 2 | test | 37 | |
| 110 | +(1 row) |
| 111 | + |
| 112 | +-- this used to fail when invoked a second time |
| 113 | +select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0" |
| 114 | +xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 115 | +<xsl:template match="@*|node()"> |
| 116 | + <xsl:copy> |
| 117 | + <xsl:apply-templates select="@*|node()"/> |
| 118 | + </xsl:copy> |
| 119 | + </xsl:template> |
| 120 | +</xsl:stylesheet>$$)::xml; |
| 121 | + xslt_process |
| 122 | +-------------- |
| 123 | + <aaa/> + |
| 124 | + |
| 125 | +(1 row) |
| 126 | + |
| 127 | +select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0" |
| 128 | +xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> |
| 129 | +<xsl:template match="@*|node()"> |
| 130 | + <xsl:copy> |
| 131 | + <xsl:apply-templates select="@*|node()"/> |
| 132 | + </xsl:copy> |
| 133 | + </xsl:template> |
| 134 | +</xsl:stylesheet>$$)::xml; |
| 135 | + xslt_process |
| 136 | +-------------- |
| 137 | + <aaa/> + |
| 138 | + |
| 139 | +(1 row) |
| 140 | + |
| 141 | +create table t1 (id integer, xml_data xml); |
| 142 | +insert into t1 (id, xml_data) |
| 143 | +values |
| 144 | +(1, '<attributes><attribute name="attr_1">Some |
| 145 | +Value</attribute></attributes>'); |
| 146 | +create index idx_xpath on t1 ( xpath_string |
| 147 | +('/attributes/attribute[@name="attr_1"]/text()', xml_data::text)); |
0 commit comments