Skip to content

XSLT

Transform and query XML documents from SQL with XSLT, XQuery and XPath

Connector software
Free and open source
Service credentials
Not needed
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/xslt/index.md to help me query XSLT with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Explode a document into numbered (seq, value) rows in document order.

Example output · captured
Connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq
Result
seq value
1 a
2 b

Quick start

Choose where to run XSLT, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'xslt' AS xslt (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-xslt-worker'
);

3. Run a query

query.sql
SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach with uvx

Needs uv. uvx builds the worker from its release tag on first attach and reuses the cached environment after that.

ATTACH 'xslt' AS xslt (
  TYPE vgi,
  LOCATION 'uvx --from git+https://github.com/Query-farm/[email protected] vgi-xslt-worker'
);

Overview

XSLT 3.0 / XQuery 3.1 / XPath 3.1 over XML for SQL (SaxonC-HE).

Catalog

Everything xslt exposes once attached — read straight from the worker's released build.

xslt 1 schema
main 1 table · 9 functions

XSLT 3.0 / XQuery 3.1 / XPath 3.1 over XML for SQL (SaxonC-HE)

Schema examples (11)
Examples (11)

Pull the string value of an XPath match out of a document.

SELECT xslt.main.xpath_string('<r><a>x</a></r>', '//a');

Test an XPath count predicate as a boolean.

SELECT xslt.main.xpath_boolean('<r><a/></r>', 'count(//a) = 1');

Read a numeric value out of a document via XPath.

SELECT xslt.main.xpath_number('<r><n>42</n></r>', 'number(//n)');

Shred every XPath match into rows with UNNEST.

SELECT UNNEST(xslt.main.xpath_array('<r><i>a</i><i>b</i></r>', '//i')) AS item;
7 more examples

Join matched values into one string with an XQuery string-join.

SELECT xslt.main.xquery('<r><i>a</i><i>b</i></r>', 'string-join(//i, ",")');

Filter to only well-formed candidate documents.

SELECT xslt.main.is_well_formed('<a></a>') AS well_formed;

Explode a document into numbered (seq, value) rows in document order.

SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq;
Result
seq value
1 a
2 b

Explode a catalog into one serialized <book> per row with xquery_rows, then pull each book's title, lang attribute and numeric price out of that row with xpath_string and xpath_number (Dune/en/9.99, Candide/fr/7.5, Emma/en/12.0).

SELECT r.seq, xslt.main.xpath_string(r.value, '/book/title') AS title,
  xslt.main.xpath_string(r.value, 'string(/book/@lang)') AS lang,
  xslt.main.xpath_number(r.value, '/book/price') AS price
FROM xslt.main.xquery_rows('<catalog><book lang="en"><title>Dune</title><price>9.99</price></book><book lang="fr"><title>Candide</title><price>7.5</price></book><book lang="en"><title>Emma</title><price>12</price></book></catalog>', 'for $b in /catalog/book return serialize($b)') AS r
ORDER BY r.seq;

Skip malformed documents with is_well_formed, then read each remaining order's id attribute and customer with xpath_string and its total (sum of qty * price over its lines) with xpath_number; the malformed order C3 is dropped (A1/acme/21.5, B7/globex/38.0).

WITH docs(id, doc) AS (VALUES (1, '<order id="A1"><customer>acme</customer><line sku="bolt" qty="2" price="9.5"/><line sku="nut" qty="10" price="0.25"/></order>'), (2, '<order id="B7"><customer>globex</customer><line sku="bolt" qty="4" price="9.5"/></order>'), (3, '<order id="C3"><customer>initech</order>')) SELECT id, xslt.main.xpath_string(doc, 'string(/order/@id)') AS order_id, xslt.main.xpath_string(doc, '/order/customer') AS customer, xslt.main.xpath_number(doc, 'sum(//line/(@qty * @price))') AS total
FROM docs
WHERE xslt.main.is_well_formed(doc)
ORDER BY id;

Shred the lines of a column of order documents with two position-aligned UNNEST(xpath_array(...)) calls, tag each line with its order's customer via xpath_string, and total the quantity per SKU (bolt 6 from acme,globex; nut 10 from acme).

WITH docs(id, doc) AS (VALUES (1, '<order id="A1"><customer>acme</customer><line sku="bolt" qty="2"/><line sku="nut" qty="10"/></order>'), (2, '<order id="B7"><customer>globex</customer><line sku="bolt" qty="4"/></order>')), lines AS (SELECT xslt.main.xpath_string(doc, '/order/customer') AS customer, UNNEST(xslt.main.xpath_array(doc, '//line/@sku')) AS sku, CAST(UNNEST(xslt.main.xpath_array(doc, '//line/@qty')) AS INTEGER) AS qty FROM docs) SELECT sku, CAST(SUM(qty) AS BIGINT) AS total_qty, string_agg(customer, ',' ORDER BY customer) AS customers
FROM lines
GROUP BY sku
ORDER BY sku;

Normalize a feed with an XSLT stylesheet (one upper-cased <item> per <entry>), then shred the transformed output into numbered rows with xpath_nodes (1 A, 2 B).

SELECT seq, value
FROM xslt.main.xpath_nodes(xslt.main.xslt('<feed><entry><t>a</t></entry><entry><t>b</t></entry></feed>', '<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><items><xsl:for-each select="//entry"><item><xsl:value-of select="upper-case(t)"/></item></xsl:for-each></items></xsl:template></xsl:stylesheet>'), '//item')
ORDER BY seq;
Tables
saxon_info 2 examples6 cols

One row describing the bundled SaxonC engine and its capabilities.

Columns
version VARCHAR
SaxonC version string of the bundled engine.
editionnot null VARCHAR
Saxon edition (HE = Home Edition, the free, non-schema-aware build).
xslt_versionnot null VARCHAR
XSLT language level the engine implements.
xquery_versionnot null VARCHAR
XQuery language level the engine implements.
xpath_versionnot null VARCHAR
XPath language level the engine implements.
schema_awarenot null BOOLEAN
Whether the engine can do XSD validation / schema-aware processing (always false on HE).
ConstraintsPRIMARY KEY (version)
Examples (2)

Read the engine version and whether XSD validation is available.

SELECT version, schema_aware FROM xslt.main.saxon_info;

Confirm the XSLT and XQuery language levels the engine implements.

SELECT xslt_version, xquery_version FROM xslt.main.saxon_info;
Link
Scalar functions
is_well_formed (xml VARCHAR) 2 examples

True if the text is well-formed XML; false if malformed (never an error)

Arguments
xml VARCHAR
Candidate XML text.
ReturnsBOOLEAN
Examples (2)

Check whether a string is well-formed XML.

SELECT xslt.main.is_well_formed('<a></a>');

Skip malformed documents with is_well_formed, then read each remaining order's id attribute and customer with xpath_string and its total (sum of qty * price over its lines) with xpath_number; the malformed order C3 is dropped (A1/acme/21.5, B7/globex/38.0).

WITH docs(id, doc) AS (VALUES (1, '<order id="A1"><customer>acme</customer><line sku="bolt" qty="2" price="9.5"/><line sku="nut" qty="10" price="0.25"/></order>'), (2, '<order id="B7"><customer>globex</customer><line sku="bolt" qty="4" price="9.5"/></order>'), (3, '<order id="C3"><customer>initech</order>')) SELECT id, xslt.main.xpath_string(doc, 'string(/order/@id)') AS order_id, xslt.main.xpath_string(doc, '/order/customer') AS customer, xslt.main.xpath_number(doc, 'sum(//line/(@qty * @price))') AS total
FROM docs
WHERE xslt.main.is_well_formed(doc)
ORDER BY id;
Link
xpath_array (xml VARCHAR, expr VARCHAR) 2 examples

String values of ALL matches of an XPath 3.1 expression, as a list -- UNNEST it to shred one document into rows

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression selecting many items.
ReturnsVARCHAR[]
Examples (2)

Shred all matching nodes into rows with UNNEST.

SELECT UNNEST(xslt.main.xpath_array('<r><i>a</i><i>b</i></r>', '//i'));

Shred the lines of a column of order documents with two position-aligned UNNEST(xpath_array(...)) calls, tag each line with its order's customer via xpath_string, and total the quantity per SKU (bolt 6 from acme,globex; nut 10 from acme).

WITH docs(id, doc) AS (VALUES (1, '<order id="A1"><customer>acme</customer><line sku="bolt" qty="2"/><line sku="nut" qty="10"/></order>'), (2, '<order id="B7"><customer>globex</customer><line sku="bolt" qty="4"/></order>')), lines AS (SELECT xslt.main.xpath_string(doc, '/order/customer') AS customer, UNNEST(xslt.main.xpath_array(doc, '//line/@sku')) AS sku, CAST(UNNEST(xslt.main.xpath_array(doc, '//line/@qty')) AS INTEGER) AS qty FROM docs) SELECT sku, CAST(SUM(qty) AS BIGINT) AS total_qty, string_agg(customer, ',' ORDER BY customer) AS customers
FROM lines
GROUP BY sku
ORDER BY sku;
Link
xpath_boolean (xml VARCHAR, expr VARCHAR) 1 example

Effective boolean value of an XPath 3.1 expression over the document

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression evaluated as a true/false test, e.g. existence or a count predicate.
ReturnsBOOLEAN
Example

Test an XPath count predicate as a boolean.

SELECT xslt.main.xpath_boolean('<r><a/></r>', 'count(//a) = 1');
Link
xpath_number (xml VARCHAR, expr VARCHAR) 1 example

Numeric (DOUBLE) value of the first XPath 3.1 match (NULL if non-numeric)

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression whose value is read as a number.
ReturnsDOUBLE
Example

Read a numeric value out of the document via XPath.

SELECT xslt.main.xpath_number('<r><n>42</n></r>', 'number(//n)');
Link
xpath_string (xml VARCHAR, expr VARCHAR) 1 example

String value of the first node/atomic matching an XPath 3.1 expression (NULL if none)

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression.
ReturnsVARCHAR
Example

First matching node's string value.

SELECT xslt.main.xpath_string('<r><a>x</a><a>y</a></r>', '//a');
Link
xquery (xml VARCHAR, query VARCHAR) 1 example

Run an XQuery 3.1 query with the document as context item; returns the serialized result

Arguments
xml VARCHAR
XML document (the context item).
query VARCHAR
XQuery 3.1 query source.
ReturnsVARCHAR
Example

Join matched values into one string with an XQuery string-join.

SELECT xslt.main.xquery('<r><i>a</i><i>b</i></r>', 'string-join(//i, ",")');
Link
xslt (xml VARCHAR, stylesheet VARCHAR) 2 examples

Transform an XML document with an XSLT 3.0 stylesheet; returns the serialized result

Arguments
xml VARCHAR
XML document to transform.
stylesheet VARCHAR
XSLT 3.0 stylesheet source.
ReturnsVARCHAR
Examples (2)

Apply an XSLT 3.0 stylesheet, lifting an inner element value into a new wrapper element.

SELECT xslt.main.xslt('<doc><n>hi</n></doc>', '<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><out><xsl:value-of select="//n"/></out></xsl:template></xsl:stylesheet>');
SELECT seq, value
FROM xslt.main.xpath_nodes(xslt.main.xslt('<feed><entry><t>a</t></entry><entry><t>b</t></entry></feed>', '<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><items><xsl:for-each select="//entry"><item><xsl:value-of select="upper-case(t)"/></item></xsl:for-each></items></xsl:template></xsl:stylesheet>'), '//item')
ORDER BY seq;
Link
Table functions
xpath_nodes (xml VARCHAR, expr VARCHAR) 2 examples

One (seq, value) row per XPath 3.1 match in a single document

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression / XQuery 3.1 query.
Returns columns
seq BIGINT
1-based position of the match in document/sequence order.
value VARCHAR
String value of the matched node/item.
Examples (2)

Number each XPath match and return it in document order.

SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq;
Result
seq value
1 a
2 b

Normalize a feed with an XSLT stylesheet (one upper-cased <item> per <entry>), then shred the transformed output into numbered rows with xpath_nodes (1 A, 2 B).

SELECT seq, value
FROM xslt.main.xpath_nodes(xslt.main.xslt('<feed><entry><t>a</t></entry><entry><t>b</t></entry></feed>', '<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><items><xsl:for-each select="//entry"><item><xsl:value-of select="upper-case(t)"/></item></xsl:for-each></items></xsl:template></xsl:stylesheet>'), '//item')
ORDER BY seq;
Link
xquery_rows (xml VARCHAR, expr VARCHAR) 2 examples

One (seq, value) row per item in an XQuery 3.1 result sequence

Arguments
xml VARCHAR
XML document.
expr VARCHAR
XPath 3.1 expression / XQuery 3.1 query.
Returns columns
seq BIGINT
1-based position of the match in document/sequence order.
value VARCHAR
String value of the matched node/item.
Examples (2)

Explode an XQuery FLWOR result into numbered rows.

SELECT seq, value
FROM xslt.main.xquery_rows('<r><i>1</i><i>2</i></r>', 'for $x in //i return $x*2')
ORDER BY seq;

Explode a catalog into one serialized <book> per row with xquery_rows, then pull each book's title, lang attribute and numeric price out of that row with xpath_string and xpath_number (Dune/en/9.99, Candide/fr/7.5, Emma/en/12.0).

SELECT r.seq, xslt.main.xpath_string(r.value, '/book/title') AS title,
  xslt.main.xpath_string(r.value, 'string(/book/@lang)') AS lang,
  xslt.main.xpath_number(r.value, '/book/price') AS price
FROM xslt.main.xquery_rows('<catalog><book lang="en"><title>Dune</title><price>9.99</price></book><book lang="fr"><title>Candide</title><price>7.5</price></book><book lang="en"><title>Emma</title><price>12</price></book></catalog>', 'for $b in /catalog/book return serialize($b)') AS r
ORDER BY r.seq;
Link

Try these queries

Pull the string value of an XPath match out of a document.

SELECT xslt.main.xpath_string('<r><a>x</a></r>', '//a')

Uses xpath_string

Test an XPath count predicate as a boolean.

SELECT xslt.main.xpath_boolean('<r><a/></r>', 'count(//a) = 1')

Uses xpath_boolean

Read a numeric value out of a document via XPath.

SELECT xslt.main.xpath_number('<r><n>42</n></r>', 'number(//n)')

Uses xpath_number

Shred every XPath match into rows with UNNEST.

SELECT UNNEST(xslt.main.xpath_array('<r><i>a</i><i>b</i></r>', '//i')) AS item

Uses xpath_array

Join matched values into one string with an XQuery string-join.

SELECT xslt.main.xquery('<r><i>a</i><i>b</i></r>', 'string-join(//i, ",")')

Uses xquery

Filter to only well-formed candidate documents.

SELECT xslt.main.is_well_formed('<a></a>') AS well_formed

Uses is_well_formed

11 more examples in the Catalog, each listed under the table or function it uses.

XSLT is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.