XSLT
Transform and query XML documents from SQL with XSLT, XQuery and XPath
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
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
| 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.
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;
INSTALL vgi FROM community;
LOAD vgi;
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'xslt' AS xslt (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-xslt:0.5.0'
);
3. Run a query
SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'xslt' AS xslt
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq
Query Farm operates XSLT for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
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;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use xslt as the catalog alias for the query below.
4. Run a query
SELECT seq, value
FROM xslt.main.xpath_nodes('<r><i>a</i><i>b</i></r>', '//i')
ORDER BY seq
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
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'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'xslt' AS xslt (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-xslt:0.5.0'
);
Overview
XSLT 3.0 / XQuery 3.1 / XPath 3.1 over XML for SQL (SaxonC-HE).
Transform, query, and shred XML directly in DuckDB SQL with full XSLT 3.0, XQuery 3.1, and XPath 3.1 support, powered by the production-grade Saxon processor.
This extension turns DuckDB into an XML processing engine. Instead of exporting data to a separate XSLT/XQuery toolchain, you can apply stylesheets, evaluate XPath expressions, run XQuery FLWOR programs, and explode XML documents into relational rows without ever leaving SQL. It is built for data engineers and analysts who land XML in columns -- SOAP/EDI payloads, RSS/Atom feeds, OOXML and SVG fragments, scientific and financial document formats -- and need to extract, reshape, or validate that markup at query time, row by row, with NULLs passed through cleanly.
Key concepts
- Per-row scalars vs. set-returning table functions. Scalars compute one value per row (a string, boolean, number, or list); table functions and the array-plus-UNNEST pattern explode a single document into many rows -- the natural way to shred XML into a relational result.
- Transform, query, and validate. XSLT reshapes documents, XPath and XQuery pull values out of them, and a well-formedness check lets you filter malformed rows before processing.
- NULL / invalid / error. A NULL input yields NULL output (or no rows); malformed XML or a bad stylesheet/expression raises a clean DuckDB error, so bad data never crashes the worker.
When to use it
Reach for this worker whenever XML lands in a DuckDB column and you need to read a value out of it, transform it into another shape, or normalize its repeated structure into rows for downstream SQL.
Under the hood
The worker is backed by SaxonC-HE, the free Home Edition of Saxonica's Saxon processor -- the reference implementation for XSLT 3.0 / XQuery 3.1 / XPath 3.1 -- via the saxonche Python bindings. A single native Saxon processor is booted once per worker and reused; compiled stylesheets and queries are cached on their source text, so a constant stylesheet applied down a column compiles once and transforms many rows. Note that SaxonC-HE is not schema-aware, so there is no XSD validation; the well-formedness check provides the strongest guarantee the free edition offers.
Learn more
Catalog
Everything xslt exposes once attached — read straight from the worker's
released build.
main 1 table · 9 functions
XSLT 3.0 / XQuery 3.1 / XPath 3.1 over XML for SQL (SaxonC-HE)
Schema 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;
| 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;
saxon_info
One row describing the bundled SaxonC engine and its capabilities.
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;
is_well_formed (xml VARCHAR)
True if the text is well-formed XML; false if malformed (never an error)
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;
xpath_array (xml VARCHAR, expr VARCHAR)
String values of ALL matches of an XPath 3.1 expression, as a list -- UNNEST it to shred one document into rows
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;
xpath_boolean (xml VARCHAR, expr VARCHAR)
Effective boolean value of an XPath 3.1 expression over the document
Test an XPath count predicate as a boolean.
SELECT xslt.main.xpath_boolean('<r><a/></r>', 'count(//a) = 1');
xpath_number (xml VARCHAR, expr VARCHAR)
Numeric (DOUBLE) value of the first XPath 3.1 match (NULL if non-numeric)
Read a numeric value out of the document via XPath.
SELECT xslt.main.xpath_number('<r><n>42</n></r>', 'number(//n)');
xpath_string (xml VARCHAR, expr VARCHAR)
String value of the first node/atomic matching an XPath 3.1 expression (NULL if none)
First matching node's string value.
SELECT xslt.main.xpath_string('<r><a>x</a><a>y</a></r>', '//a');
xquery (xml VARCHAR, query VARCHAR)
Run an XQuery 3.1 query with the document as context item; returns the serialized result
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, ",")');
xslt (xml VARCHAR, stylesheet VARCHAR)
Transform an XML document with an XSLT 3.0 stylesheet; returns the serialized result
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;
xpath_nodes (xml VARCHAR, expr VARCHAR)
One (seq, value) row per XPath 3.1 match in a single document
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;
| 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;
xquery_rows (xml VARCHAR, expr VARCHAR)
One (seq, value) row per item in an XQuery 3.1 result sequence
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;
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.
Related workers
Jolt
File formats & encodings
Reshape, rename, and validate JSON documents with declarative Bazaarvoice Jolt specs
ASN.1
File formats & encodings
Decode ASN.1 BER/DER blobs and SNMP, Kerberos, LDAP, CMS, PKCS and OCSP messages into SQL rows
BSON
File formats & encodings
Query BSON documents and move them between files and tables