Debian Codegraph @

contrib/xml2/expected/xml2_1.out

raw
1 CREATE EXTENSION xml2;
2 select query_to_xml('select 1 as x',true,false,'');
3 query_to_xml
4 ---------------------------------------------------------------
5 <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
6 +
7 <row> +
8 <x>1</x> +
9 </row> +
10 +
11 </table> +
12
13 (1 row)
14
15 select xslt_process( query_to_xml('select x from generate_series(1,5) as
16 x',true,false,'')::text,
17 $$<xsl:stylesheet version="1.0"
18 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
19 <xsl:output method="xml" indent="yes" />
20 <xsl:template match="*">
21 <xsl:copy>
22 <xsl:copy-of select="@*" />
23 <xsl:apply-templates />
24 </xsl:copy>
25 </xsl:template>
26 <xsl:template match="comment()|processing-instruction()">
27 <xsl:copy />
28 </xsl:template>
29 </xsl:stylesheet>
30 $$::text);
31 ERROR: xslt_process() is not available without libxslt
32 CREATE TABLE xpath_test (id integer NOT NULL, t xml);
33 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
34 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
35 as t(id int4);
36 id
37 ----
38 (0 rows)
39
40 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
41 as t(id int4, doc int4);
42 id | doc
43 ----+-----
44 1 | 1
45 (1 row)
46
47 DROP TABLE xpath_test;
48 CREATE TABLE xpath_test (id integer NOT NULL, t text);
49 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
50 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
51 as t(id int4);
52 id
53 ----
54 (0 rows)
55
56 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
57 as t(id int4, doc int4);
58 id | doc
59 ----+-----
60 1 | 1
61 (1 row)
62
63 create table articles (article_id integer, article_xml xml, date_entered date);
64 insert into articles (article_id, article_xml, date_entered)
65 values (2, '<article><author>test</author><pages>37</pages></article>', now());
66 SELECT * FROM
67 xpath_table('article_id',
68 'article_xml',
69 'articles',
70 '/article/author|/article/pages|/article/title',
71 'date_entered > ''2003-01-01'' ')
72 AS t(article_id integer, author text, page_count integer, title text);
73 article_id | author | page_count | title
74 ------------+--------+------------+-------
75 2 | test | 37 |
76 (1 row)
77
78 -- this used to fail when invoked a second time
79 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
80 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
81 <xsl:template match="@*|node()">
82 <xsl:copy>
83 <xsl:apply-templates select="@*|node()"/>
84 </xsl:copy>
85 </xsl:template>
86 </xsl:stylesheet>$$)::xml;
87 ERROR: xslt_process() is not available without libxslt
88 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
89 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
90 <xsl:template match="@*|node()">
91 <xsl:copy>
92 <xsl:apply-templates select="@*|node()"/>
93 </xsl:copy>
94 </xsl:template>
95 </xsl:stylesheet>$$)::xml;
96 ERROR: xslt_process() is not available without libxslt
97 create table t1 (id integer, xml_data xml);
98 insert into t1 (id, xml_data)
99 values
100 (1, '<attributes><attribute name="attr_1">Some
101 Value</attribute></attributes>');
102 create index idx_xpath on t1 ( xpath_string
103 ('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
104 SELECT xslt_process('<employee><name>cim</name><age>30</age><pay>400</pay></employee>'::text, $$<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
105 <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
106 <xsl:strip-space elements="*"/>
107 <xsl:param name="n1"/>
108 <xsl:param name="n2"/>
109 <xsl:param name="n3"/>
110 <xsl:param name="n4"/>
111 <xsl:param name="n5" select="'me'"/>
112 <xsl:template match="*">
113 <xsl:element name="samples">
114 <xsl:element name="sample">
115 <xsl:value-of select="$n1"/>
116 </xsl:element>
117 <xsl:element name="sample">
118 <xsl:value-of select="$n2"/>
119 </xsl:element>
120 <xsl:element name="sample">
121 <xsl:value-of select="$n3"/>
122 </xsl:element>
123 <xsl:element name="sample">
124 <xsl:value-of select="$n4"/>
125 </xsl:element>
126 <xsl:element name="sample">
127 <xsl:value-of select="$n5"/>
128 </xsl:element>
129 <xsl:element name="sample">
130 <xsl:value-of select="$n6"/>
131 </xsl:element>
132 <xsl:element name="sample">
133 <xsl:value-of select="$n7"/>
134 </xsl:element>
135 <xsl:element name="sample">
136 <xsl:value-of select="$n8"/>
137 </xsl:element>
138 <xsl:element name="sample">
139 <xsl:value-of select="$n9"/>
140 </xsl:element>
141 <xsl:element name="sample">
142 <xsl:value-of select="$n10"/>
143 </xsl:element>
144 <xsl:element name="sample">
145 <xsl:value-of select="$n11"/>
146 </xsl:element>
147 <xsl:element name="sample">
148 <xsl:value-of select="$n12"/>
149 </xsl:element>
150 </xsl:element>
151 </xsl:template>
152 </xsl:stylesheet>$$::text, 'n1="v1",n2="v2",n3="v3",n4="v4",n5="v5",n6="v6",n7="v7",n8="v8",n9="v9",n10="v10",n11="v11",n12="v12"'::text);
153 ERROR: xslt_process() is not available without libxslt
154 -- xpath_nodeset()
155 SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages')
156 FROM articles;
157 xpath_nodeset
158 ----------------------------------------
159 <author>test</author><pages>37</pages>
160 (1 row)
161
162 SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
163 'item_without_toptag')
164 FROM articles;
165 xpath_nodeset
166 ------------------------------------------------------------------------------------------------------------------------------
167 <item_without_toptag><author>test</author></item_without_toptag><item_without_toptag><pages>37</pages></item_without_toptag>
168 (1 row)
169
170 SELECT xpath_nodeset(article_xml::text, '/article/author|/article/pages',
171 'result', 'item')
172 FROM articles;
173 xpath_nodeset
174 -----------------------------------------------------------------------------------
175 <result><item><author>test</author></item><item><pages>37</pages></item></result>
176 (1 row)
177
178 -- namespace node
179 SELECT xpath_nodeset('<root xmlns:foo="http://icl.com/saxon"/>',
180 '//namespace::foo');
181 xpath_nodeset
182 ----------------------
183 http://icl.com/saxon
184 (1 row)
185
186 -- xpath_list()
187 SELECT xpath_list(article_xml::text, '/article/author|/article/pages')
188 FROM articles;
189 xpath_list
190 ------------
191 test,37
192 (1 row)
193
194 SELECT xpath_list(article_xml::text, '/article/author|/article/pages', '|')
195 FROM articles;
196 xpath_list
197 ------------
198 test|37
199 (1 row)
200
201 -- possible security exploit
202 SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
203 $$<xsl:stylesheet version="1.0"
204 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
205 xmlns:sax="http://icl.com/saxon"
206 extension-element-prefixes="sax">
207
208 <xsl:template match="//foo">
209 <sax:output href="0wn3d.txt" method="text">
210 <xsl:value-of select="'0wn3d via xml2 extension and libxslt'"/>
211 <xsl:apply-templates/>
212 </sax:output>
213 </xsl:template>
214 </xsl:stylesheet>$$);
215 ERROR: xslt_process() is not available without libxslt
216 -- empty output
217 select xslt_process('<aaa/>',
218 $$<xsl:stylesheet version="1.0"
219 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
220 </xsl:stylesheet>$$);
221 ERROR: xslt_process() is not available without libxslt