1CREATE EXTENSION xml2;
2select 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
15select xslt_process( query_to_xml('select x from generate_series(1,5) as
16x',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);
31ERROR:  xslt_process() is not available without libxslt
32CREATE TABLE xpath_test (id integer NOT NULL, t xml);
33INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
34SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
35as t(id int4);
36 id
37----
38(0 rows)
39
40SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
41as t(id int4, doc int4);
42 id | doc
43----+-----
44  1 |   1
45(1 row)
46
47DROP TABLE xpath_test;
48CREATE TABLE xpath_test (id integer NOT NULL, t text);
49INSERT INTO xpath_test VALUES (1, '<doc><int>1</int></doc>');
50SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
51as t(id int4);
52 id
53----
54(0 rows)
55
56SELECT * FROM xpath_table('id', 't', 'xpath_test', '/doc/int', 'true')
57as t(id int4, doc int4);
58 id | doc
59----+-----
60  1 |   1
61(1 row)
62
63create table articles (article_id integer, article_xml xml, date_entered date);
64insert into articles (article_id, article_xml, date_entered)
65values (2, '<article><author>test</author><pages>37</pages></article>', now());
66SELECT * FROM
67xpath_table('article_id',
68            'article_xml',
69            'articles',
70            '/article/author|/article/pages|/article/title',
71            'date_entered > ''2003-01-01'' ')
72AS 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
79select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
80xmlns: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;
87ERROR:  xslt_process() is not available without libxslt
88select xslt_process('<aaa/>',$$<xsl:stylesheet version="1.0"
89xmlns: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;
96ERROR:  xslt_process() is not available without libxslt
97create table t1 (id integer, xml_data xml);
98insert into t1 (id, xml_data)
99values
100(1, '<attributes><attribute name="attr_1">Some
101Value</attribute></attributes>');
102create index idx_xpath on t1 ( xpath_string
103('/attributes/attribute[@name="attr_1"]/text()', xml_data::text));
104SELECT 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);
153ERROR:  xslt_process() is not available without libxslt
154-- possible security exploit
155SELECT xslt_process('<xml><foo>Hello from XML</foo></xml>',
156$$<xsl:stylesheet version="1.0"
157      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
158      xmlns:sax="http://icl.com/saxon"
159      extension-element-prefixes="sax">
160
161  <xsl:template match="//foo">
162    <sax:output href="0wn3d.txt" method="text">
163      <xsl:value-of select="'0wn3d via xml2 extension and libxslt'"/>
164      <xsl:apply-templates/>
165    </sax:output>
166  </xsl:template>
167</xsl:stylesheet>$$);
168ERROR:  xslt_process() is not available without libxslt
169