CSV functions
xxf:csv-to-xml()
[SINCE Orbeon Forms 2026.1]
The xxf:csv-to-xml() function takes a CSV string and returns an XML document following the XForms 2.0 CSV conversion scheme.
xxf:csv-to-xml() as document-node()?
xxf:csv-to-xml($csv as xs:string?) as document-node()?
xxf:csv-to-xml($csv as xs:string?, $header as xs:boolean?) as document-node()?Parameters
$csv:The CSV string to parse.
If omitted, the context item is converted to a string using the
string()function.If
$csvis the empty sequence, the function returns the empty sequence.
$header:Optional parameter indicating whether the first row of the CSV input is a header row.
Defaults to
true().Accepts a boolean (
true()orfalse()).
XML structure
The returned document has a <csv> root element:
With headers (
$headeristrue(), the default):The first row of the CSV input is used as a header row.
Each header value is converted into a valid XML
NCNameto be used as an element name:Leading and trailing whitespace is trimmed.
An empty or blank header becomes
_.Characters that are not valid in an
NCName(such as spaces or punctuation) are replaced with_.If the first character is a valid
NCNamecharacter but not a validNCNamestart character (such as a digit or-),_is prepended (for example,123becomes_123).
An
<h>element is created as the first child of<csv>, containing one child element per header column. Each child element is named using the derivedNCNameand has the original header string as its text content.Each subsequent CSV row is represented as an
<r>element under<csv>. Within each<r>, each field is represented by an element named after the corresponding column's derivedNCName(or<v>if the row has more fields than the header row).
Without headers (
$headerisfalse()):No
<h>element is created.Every CSV row is represented as an
<r>element under<csv>.Each field within an
<r>element is represented as a<v>element.
CSV parsing rules
Fields are separated by commas (
,), and rows are separated byCRLF(\r\n) orLF(\n).Unquoted fields have leading and trailing whitespace trimmed.
Fields enclosed in double quotes (
"...") preserve whitespace, commas, and line breaks.Double quotes inside a quoted field are escaped by doubling them (
"").
Examples
With a header row (default):
xxf:csv-to-xml($csv) returns:
Without a header row:
xxf:csv-to-xml($csv, false()) returns:
xxf:xml-to-csv()
[SINCE Orbeon Forms 2026.1]
The xxf:xml-to-csv() function takes an XML document or element following the XForms 2.0 CSV conversion scheme and converts it to a CSV string.
Parameters
$xml:A document node or element node (typically the document returned by
xxf:csv-to-xml(), its<csv>root element, or a single<r>row element).If omitted, the context item is used.
If
$xmlis the empty sequence, the function returns the empty sequence.
$header:Optional parameter indicating whether a header row should be included in the CSV output.
Defaults to
true().Accepts a boolean (
true()orfalse()).
Conversion rules
Header row:
When
$headeristrue()(the default):If an
<h>child element is present, the header row is built from the children of<h>(using each child's trimmed text value if non-blank, or its local element name otherwise).If no
<h>child element is present and the first<r>element has child elements whose names are not all<v>, the local names of the first<r>element's children are used as the header row.Otherwise, no header row is emitted.
When
$headerisfalse(), no header row is emitted, even if an<h>element is present in$xml.
Data rows:
Each
<r>element produces a CSV row with the string values of its child elements.
Formatting and escaping:
Fields are separated by commas (
,), and rows are separated byCRLF(\r\n).Fields containing a comma (
,), double quote ("), carriage return (\r), line feed (\n), or leading/trailing spaces are enclosed in double quotes ("..."), with inner double quotes escaped as"".
Last updated