<literal>Value
1,Value 2,Value 3</literal> if <parameter>separator</parameter>
is <literal>,</literal>.
</para></entry>
</row>
<row>
<entry role="func_table_entry"><para role="func_signature">
<function>xpath_list</function> ( <parameter>document</parameter> <type>text</type>, <parameter>query</parameter> <type>text</type> )
<returnvalue>text</returnvalue>
</para>
<para>
This is a wrapper for the above function that uses <literal>,</literal>
as the separator.
</para></entry>
</row>
</tbody>
</tgroup>
</table>
</sect2>
<sect2 id="xml2-xpath-table">
<title><literal>xpath_table</literal></title>
<indexterm>
<primary>xpath_table</primary>
</indexterm>
<synopsis>
xpath_table(text key, text document, text relation, text xpaths, text criteria) returns setof record
</synopsis>
<para>
<function>xpath_table</function> is a table function that evaluates a set of XPath
queries on each of a set of documents and returns the results as a
table. The primary key field from the original document table is returned
as the first column of the result so that the result set
can readily be used in joins. The parameters are described in
<xref linkend="xml2-xpath-table-parameters"/>.
</para>
<table id="xml2-xpath-table-parameters">
<title><function>xpath_table</function> Parameters</title>
<tgroup cols="2">
<colspec colname="col1" colwidth="1*"/>
<colspec colname="col2" colwidth="2*"/>
<thead>
<row>
<entry>Parameter</entry>
<entry>Description</entry>
</row>
</thead>
<tbody>
<row>
<entry><parameter>key</parameter></entry>
<entry>
<para>
the name of the <quote>key</quote> field — this is just a field to be used as
the first column of the output table, i.e., it identifies the record from
which each output row came (see note below about multiple values)
</para>
</entry>
</row>
<row>
<entry><parameter>document</parameter></entry>
<entry>
<para>
the name of the field containing the XML document
</para>
</entry>
</row>
<row>
<entry><parameter>relation</parameter></entry>
<entry>
<para>
the name of the table or view containing the documents
</para>
</entry>
</row>
<row>
<entry><parameter>xpaths</parameter></entry>
<entry>
<para>
one or more XPath expressions, separated by <literal>|</literal>
</para>
</entry>
</row>
<row>
<entry><parameter>criteria</parameter></entry>
<entry>
<para>
the contents of the WHERE clause. This cannot be omitted, so use
<literal>true</literal> or <literal>1=1</literal> if you want to
process all the rows in the relation
</para>
</entry>
</row>
</tbody>
</tgroup>
</table>
<para>
These parameters (except the XPath strings) are just substituted
into a plain SQL SELECT statement, so you have some flexibility — the
statement is
</para>
<para>
<literal>
SELECT <key>, <document> FROM <relation> WHERE <criteria>
</literal>
</para>
<para>
so those parameters can be <emphasis>anything</emphasis> valid in those particular
locations. The result from this SELECT needs to return exactly two
columns (which it will unless you try to list multiple fields for key
or document). Beware that this simplistic approach requires that you
validate any user-supplied values to avoid SQL injection attacks.
</para>
<para>
The function has to be used in a <literal>FROM</literal> expression, with an
<literal>AS</literal> clause to specify the output columns; for example
<programlisting>
SELECT * FROM
xpath_table('article_id',
'article_xml',
'articles',