2 select query_to_xml('select 1 as x',true,false,'');
4 ---------------------------------------------------------------
5 <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
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="*">
22 <xsl:copy-of select="@*" />
23 <xsl:apply-templates />
26 <xsl:template match="comment()|processing-instruction()">
32 ---------------------------------------------------------------
33 <?xml version="1.0"?> +
34 <table xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">+
60 CREATE TABLE xpath_test (id integer NOT NULL, t xml);
61 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
62 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
68 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
69 as t(id int4, doc int4);
75 DROP TABLE xpath_test;
76 CREATE TABLE xpath_test (id integer NOT NULL, t text);
77 INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
78 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
84 SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
85 as t(id int4, doc int4);
91 create table articles (article_id integer, article_xml xml, date_entered date);
92 insert into articles (article_id, article_xml, date_entered)
93 values (2, '<article><author>test</author><pages>37</pages></article>', now());
95 xpath_table('article_id',
98 '/article/author|/article/pages|/article/title',
99 'date_entered > ''2003-01-01'' ')
100 AS t(article_id integer, author text, page_count integer, title text);
101 article_id | author | page_count | title
102 ------------+--------+------------+-------
106 -- this used to fail when invoked a second time
107 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
108 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
109 <xsl:template match="@*|node()">
111 <xsl:apply-templates select="@*|node()"/>
114 </xsl:stylesheet>$$)::xml;
121 select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
122 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
123 <xsl:template match="@*|node()">
125 <xsl:apply-templates select="@*|node()"/>
128 </xsl:stylesheet>$$)::xml;
135 create table t1 (id integer, xml_data xml);
136 insert into t1 (id, xml_data)
138 (1, '<attributes><attribute name="attr_1">Some
139 Value</attribute></attributes>');
140 create index idx_xpath on t1 ( xpath_string
141 ('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
142 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">
143 <xsl:output method="xml" omit-xml-declaration="yes" indent="yes"/>
144 <xsl:strip-space elements="*"/>
145 <xsl:param name="n1"/>
146 <xsl:param name="n2"/>
147 <xsl:param name="n3"/>
148 <xsl:param name="n4"/>
149 <xsl:param name="n5" select="'me'"/>
150 <xsl:template match="*">
151 <xsl:element name="samples">
152 <xsl:element name="sample">
153 <xsl:value-of select="$n1"/>
155 <xsl:element name="sample">
156 <xsl:value-of select="$n2"/>
158 <xsl:element name="sample">
159 <xsl:value-of select="$n3"/>
161 <xsl:element name="sample">
162 <xsl:value-of select="$n4"/>
164 <xsl:element name="sample">
165 <xsl:value-of select="$n5"/>
167 <xsl:element name="sample">
168 <xsl:value-of select="$n6"/>
170 <xsl:element name="sample">
171 <xsl:value-of select="$n7"/>
173 <xsl:element name="sample">
174 <xsl:value-of select="$n8"/>
176 <xsl:element name="sample">
177 <xsl:value-of select="$n9"/>
179 <xsl:element name="sample">
180 <xsl:value-of select="$n10"/>
182 <xsl:element name="sample">
183 <xsl:value-of select="$n11"/>
185 <xsl:element name="sample">
186 <xsl:value-of select="$n12"/>
190 </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);
192 ------------------------
194 <sample>v1</sample> +
195 <sample>v2</sample> +
196 <sample>v3</sample> +
197 <sample>v4</sample> +
198 <sample>v5</sample> +
199 <sample>v6</sample> +
200 <sample>v7</sample> +
201 <sample>v8</sample> +
202 <sample>v9</sample> +
203 <sample>v10</sample>+
204 <sample>v11</sample>+
205 <sample>v12</sample>+
210 -- possible security exploit
211 SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
212 $$<xsl:stylesheet version="1.0"
213 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
214 xmlns:sax="http://icl.com/saxon"
215 extension-element-prefixes="sax">
217 <xsl:template match="//foo">
218 <sax:output href="0wn3d.txt" method="text">
219 <xsl:value-of select="'0wn3d via xml2 extension and libxslt'"/>
220 <xsl:apply-templates/>
223 </xsl:stylesheet>$$);
224 ERROR: failed to apply stylesheet