API - xokomola/origami GitHub Wiki

Back: Home

Modules

Origami - micro-templating library for XQuery 3.1

o:add-attr-token, o:add-class, o:advise-attr, o:advise-attrs, o:after, o:apply, o:attributes, o:attrs, o:before, o:builder, o:children, o:choose, o:comp, o:compile-rules, o:compile-stylesheet, o:conj, o:copy, o:doc, o:filter, o:flatten, o:for-each, o:get-html, o:has-attr, o:has-attrs, o:has-handler, o:head, o:identity, o:insert, o:insert-after, o:insert-before, o:is-element, o:is-handler, o:is-text-node, o:json, o:map-builder, o:name, o:name-resolver, o:ns, o:ns-builder, o:ntext, o:parse-csv, o:parse-html, o:parse-json, o:postwalk, o:prewalk, o:qname, o:qname-resolver, o:read-csv, o:read-html, o:read-json, o:read-text, o:read-xml, o:remove-att-token, o:remove-attr, o:remove-attr-handlers, o:remove-class, o:remove-handler, o:rename, o:repeat, o:replace, o:repr, o:select, o:seq, o:set-attr, o:set-attr-handlers, o:set-attrs, o:set-handler, o:size, o:sort, o:tag, o:tail, o:text, o:transform, o:transformer, o:tree-seq, o:unwrap, o:wrap, o:xf-builder, o:xml, o:xslt, o:xslt-builder

See: source

Functions

o:add-attr-token(
  $attr as xs:string,
  $tokens as xs:string*)
  as function(array(*)) as array(*)
o:add-attr-token(
  $node as array(*),
  $attr as xs:string,
  $tokens as xs:string*)
  as array(*)
o:add-class(
  $class-names as xs:string*)
  as function(array(*)) as array(*)

Create a node transformer that adds one or more class names to each element in the nodes passed.

o:add-class(
  $node as array(*),
  $class-names as xs:string*)
  as array(*)

Add one or more $names to the class attribute of $element. If it doesn't exist it is added.

o:advise-attr(
  $name as xs:string,
  $value as item()*)
  as function(array(*)) as array(*)
o:advise-attr(
  $node as array(*),
  $name as xs:string,
  $value as item()*)
  as array(*)
o:advise-attrs(
  $attrs as map(*))
  as function(array(*)) as array(*)

Set attributes that aren't already set on $node.

o:advise-attrs(
  $node as array(*),
  $attrs as map(*))
  as array(*)
o:after(
  $after as item()*)
  as function(item()) as item()*

Create a node transformer that inserts $after after the nodes passed in.

o:after(
  $node as item(),
  $after as item()*)
  as item()*

Inserts the $after nodes, after $nodes.

o:apply(
  $nodes as item()*)
  as item()*
o:apply(
  $nodes as item()*,
  $data as item()*)
  as item()*
o:apply(
  $nodes as item()*,
  $current as array(*),
  $data as item()*)
  as item()*
o:attributes(
  $node as array(*)?)
  as map(*)?
o:attrs(
  $node as array(*)?)
  as map(*)

Always returns a map even if element has no attributes.

o:before(
  $before as item()*)
  as function(item()) as item()*

Create a node transformer that inserts $before before the nodes passed in.

o:before(
  $node as item(),
  $before as item()*)
  as item()*

Inserts the $before nodes, before $nodes.

o:builder() as map(*)
o:builder(
  $rules as item()*)
  as map(*)
o:builder(
  $rules as item()*,
  $options as map(*))
  as map(*)
o:children(
  $node as array(*)?)
  as item()*
o:choose(
  $selector as item()*,
  $choices as function(*))
  as item()*

Selector:

  • function($node) => int*|key*
  • int*
  • key*

Choices:

  • array: selector => int
  • map: selector =>
  • function(int*|key*) => fn(nodes)
o:choose(
  $node as item(),
  $selector as item()*,
  $choices as function(*))
  as item()*
o:comp(
  $fns as item()*)
  as function(item()*) as item()*

Returns a function that composes the passed functions. All functions have arity 1. TODO: what about other arities? TODO: in Clojure do evaluates in sequence, maybe use compose.

o:compile-rules(
  $rules as array(*)+)
  as map(*)*
o:compile-stylesheet(
  $rules as map(*))
  as element(*)
o:compile-stylesheet(
  $rules as map(*),
  $namespaces as map(*))
  as element(*)
o:conj(
  $items as item()*)
  as item()*

Returns a function that conjoins items to a sequence. The type of sequence is determined by the type of the $seq argument.

o:conj(
  $seq as item()*,
  $items as item()*)
  as item()*
o:copy() as function(item()*) as item()*

Copy nodes without any transformation.

o:copy(
  $node as item())
  as item()*
o:doc(
  $items as item()*)
  as item()*

Converts input nodes to an Origami document.

o:doc(
  $nodes as item()*,
  $builder as item()*)
  as item()*
o:filter(
  $nodes as item()*,
  $fn as function(item()) as xs:boolean)
  as item()*
o:filter(
  $fn as function(item()) as xs:boolean)
  as item()*
o:flatten() as function(item()*) as item()*
o:flatten(
  $nodes as item()*)
  as item()*
o:for-each(
  $nodes as item()*,
  $fn as function(item()) as item()*)
  as item()*
o:for-each(
  $fn as function(item()) as item()*)
  as item()*
o:get-html(
  $uri as xs:string)
  as item()*
o:get-html(
  $uri as xs:string,
  $options as map(xs:string, xs:string))
  as item()*
o:has-attr(
  $node as item()?,
  $attr as xs:string)
  as xs:boolean
o:has-attrs(
  $node as item()?)
  as xs:boolean
o:has-handler(
  $element as array(*))
  as xs:boolean
o:head(
  $node as array(*)?)
  as item()?
o:identity(
  $x as item()*)
  as item()*

Returns the argument unmodified.

o:insert(
  $content as item()*)
  as function(*)

Create a node transformer that replaces the child nodes of an element with $content.

o:insert(
  $node as array(*),
  $content as item()*)
  as item()*

Replace the child nodes of $element with $content.

o:insert-after(
  $append as item()*)
  as function(array(*)) as array(*)

Create a node transformer that appends $append nodes to the child nodes of each element of $nodes.

o:insert-after(
  $node as array(*),
  $append as item()*)
  as array(*)

Inserts $append nodes to the child nodes of each element in $nodes.

o:insert-before(
  $prepend as item()*)
  as function(array(*)) as array(*)

Create a node transformer that prepends $prepend nodes to the child nodes of each element of $nodes.

o:insert-before(
  $node as array(*),
  $prepend as item()*)
  as array(*)

Inserts $prepend nodes before the first child node of each element in $nodes.

o:is-element(
  $node as item()?)
  as xs:boolean
o:is-handler(
  $node as item()?)
  as xs:boolean
o:is-text-node(
  $node as item()?)
  as xs:boolean
o:json(
  $nodes as item()*)
  as xs:string

Converts mu-nodes to JSON with the default name resolver.

o:json(
  $nodes as item()*,
  $name-resolver as function(*))
  as xs:string

Converts mu-nodes to JSON using a name-resolver.

o:map-builder(
  $rules as map(*),
  $options as map(*))
  as map(*)
o:name(
  $name as xs:string,
  $resolver as function(xs:string) as xs:string?)
  as xs:string

Resolve a name using the resolver function (may be a map). If the resolver returns the empty sequence this will return the original name.

o:name-resolver(
  $resolver as function(xs:string) as xs:string?)
  as function(xs:string) as xs:string

Returns a name resolver function from the namespace map passed as it's argument.

o:ns(
  $namespaces as item()*)
  as map(*)

Get a namespace map from XML nodes. Note that this assumes somewhat sane[1] namespace usage. The resulting map will contain a prefix/URI entry for each used prefix but it will not re-bind a prefix to a different URI at descendant nodes. Unused prefixes are dropped. The result can be used when serializing back to XML but results may be not what you expect if you pass insane XML fragments.

[1] http://lists.xml.org/archives/xml-dev/200204/msg00170.html

o:ns-builder(
  $namespaces as item()*)
  as map(*)
o:ns-builder(
  $builder as map(*),
  $namespaces as item()*)
  as map(*)
o:ntext(
  $nodes as item()*)
  as xs:string?

Create a node transformer that returns a text node with the space normalized string value of a node.

o:parse-csv(
  $text as xs:string*)
  as array(*)*
o:parse-csv(
  $text as xs:string*,
  $options as map(xs:string, item()))
  as array(*)*
o:parse-html(
  $text as xs:string*)
  as element()

Note that binary or strings can be passed to html:parse, in which case encoding can be used to override automatic detection. We can also just pass in a seq of strings.

o:parse-html(
  $text as xs:string*,
  $options as map(xs:string, item()))
  as element()
o:parse-json(
  $text as xs:string*)
  as item()?

Options:

  • liberal: true() or false() [default, RFC7159 parsing]
  • unescape: true() or false() [default true()]
  • duplicates: reject, use-first, use-last [default use-last]

See: http://www.w3.org/TR/xpath-functions-31/#func-parse-json

o:parse-json(
  $text as xs:string*,
  $options as map(xs:string, item()))
  as item()?
o:postwalk(
  $form as item()*,
  $fn as function(*))
  as item()*

Generic walker function (depth-first).

o:prewalk(
  $form as item()*,
  $fn as function(*))
  as item()*

Generic walker function (breadth-first).

o:qname(
  $name as xs:string)
  as xs:QName

Returns a QName in "no namespace". Throws a dynamic error FOCA0002 with a prefixed name.

o:qname(
  $name as xs:string,
  $resolver as item())
  as xs:QName

Returns a QName from a string taking the namespace URI from the namespace map passed as it's second argument. Throws a dynamic error FOCA0002 with a name which is not in correct lexical form. Returns a QName in a made-up namespace URI if the prefix is not defined in the namespace map.

o:qname-resolver(
  $resolver as item())
  as function(xs:string) as xs:QName

Returns a QName resolver function from the namespace map passed as it's argument.

o:read-csv(
  $uri as xs:string)
  as array(*)*

Options:

  • encoding (for text decoding)
  • separator: comma, semicolon, tab, space or any single character (default comma)
  • lax: yes, no (yes) lax approach to parsing qnames to json names
  • quotes: yes, no (yes)
  • backslashes: yes, no (no)
o:read-csv(
  $uri as xs:string,
  $options as map(xs:string, item()))
  as array(*)*
o:read-html(
  $uri as xs:string?)
  as element()

Read and parse HTML with the Tagsoup parser (although this could be changed). If Tagsoup is not available it will fallback to parsing well-formed XML.

For options see: http://docs.basex.org/wiki/Parsers#TagSoup_Options

o:read-html(
  $uri as xs:string?,
  $options as map(xs:string, item()))
  as element()
o:read-json(
  $uri as xs:string)
  as item()?
o:read-json(
  $uri as xs:string,
  $options as map(xs:string, item()))
  as item()?
o:read-text(
  $uri as xs:string?)
  as xs:string*

Options:

  • lines: true() or false()
  • encoding
o:read-text(
  $uri as xs:string?,
  $options as map(xs:string, item()))
  as xs:string*
o:read-xml(
  $uri as xs:string)
  as document-node()?
o:read-xml(
  $uri as xs:string,
  $options as map(xs:string, item()))
  as document-node()?

XQuery does not support options for controlling the parsing of XML. This function allows the use of proprietary fetch:xml to specify some options to the XML parser.

Also there's a difference with fn:doc in that each call fetches a new document and it is discarded after the query ends.

For options see: http://docs.basex.org/wiki/Options#Parsing

o:remove-att-token(
  $att as xs:string,
  $tokens as xs:string*)
  as function(array(*)) as array(*)
o:remove-att-token(
  $node as array(*),
  $att as xs:string,
  $tokens as xs:string*)
  as array(*)
o:remove-attr(
  $attr-names as xs:string*)
  as function(array(*)) as array(*)

Create a node transformer that remove attributes.

If a name cannot be used as an attribute name (xs:QName) then it will be silently ignored.

o:remove-attr(
  $node as array(*),
  $attr-names as xs:string*)
  as array(*)

Remove attributes from each element in $nodes.

o:remove-attr-handlers(
  $element as array(*))
  as array(*)
o:remove-attr-handlers() as function(*)
o:remove-class(
  $class-names as xs:string*)
  as function(array(*)) as array(*)

Create a node transformer that removes one or more $names from the class attribute. If the class attribute is empty after removing names it will be removed from the element.

o:remove-class(
  $node as array(*),
  $class-names as xs:string*)
  as array(*)

Remove one or more $names from the class attribute of $element. If the class attribute is empty after removing names it will be removed from the element.

o:remove-handler(
  $element as array(*))
  as array(*)
o:remove-handler() as function(*)
o:rename(
  $element-name as item())
  as function(array(*)) as array(*)

Create a node-transformer that renames element nodes, passing non-element nodes and element child nodes through unmodified.

Renaming can be done using a:

  • xs:string: renames all elements
  • map(*): looks up the element name in the map and uses the value as the new name
o:rename(
  $node as array(*),
  $element-name as item())
  as array(*)

Renames elements in $nodes.

o:repeat(
  $node as item()*,
  $repeat-seq as item()*,
  $fn as function(*))
  as item()*

Repeat the incoming nodes and feed them through the function.

o:repeat(
  $repeat-seq as item()*,
  $fn as function(*))
  as function(item()*) as item()*

A node repeating function, also works with prepped node handlers

o:repeat(
  $repeat-seq as item()*)
  as item()*
o:replace() as function(*)
o:replace(
  $content as item()*)
  as function(*)
o:replace(
  $node as array(*),
  $content as item()*)
  as item()*
o:repr(
  $nodes as item()*)
  as item()*

Renders a representation of a document where all functions are shown with a string representation. This can be used for inspection and in tests. Function items cannot be atomized or compared.

o:select(
  $steps as array(*))
  as function(item()*) as item()*
o:select(
  $nodes as item()*,
  $steps as array(*))
  as item()*
o:seq() as function(item()*) as item()*

Returns a function that transforms an array or map into a sequence. A map item will be transformed into a sequence of two item arrays.

o:seq(
  $nodes as item()*)
  as item()*

Transforms an array or map item into a sequence.

o:set-attr(
  $name as xs:string,
  $value as item()*)
  as function(array(*)) as array(*)
o:set-attr(
  $node as array(*),
  $name as xs:string,
  $value as item()*)
  as array(*)
o:set-attr-handlers(
  $element as array(*),
  $handlers as map(xs:string, function(*)))
  as array(*)
o:set-attr-handlers(
  $handlers as map(xs:string, function(*)))
  as function(*)
o:set-attrs(
  $attrs as map(*))
  as function(array(*)) as array(*)

Create a node transformer that sets attributes using a map on each element in the nodes passed.

o:set-attrs(
  $node as array(*),
  $attrs as map(*))
  as array(*)

Set attributes using a map on $node.

o:set-handler(
  $element as array(*),
  $handler as function(*)?)
  as array(*)
o:set-handler(
  $handler as function(*)?)
  as function(*)
o:size(
  $node as array(*)?)
  as xs:integer

Returns the size of contents (child nodes not attributes).

o:sort(
  $input as item()*,
  $key as function(item()) as xs:anyAtomicType*)
  as item()*
o:sort(
  $key as function(item()) as xs:anyAtomicType*)
  as item()*
o:sort() as function(item()*) as item()*
o:tag(
  $node as array(*)?)
  as item()?
o:tail(
  $node as array(*)?)
  as item()*
o:text(
  $nodes as item()*)
  as xs:string?

Outputs the text value of $nodes.

o:transform(
  $nodes as item()*,
  $rules as array(*)+)
  as item()*
o:transform(
  $nodes as item()*,
  $rules as array(*)+,
  $options as map(*))
  as item()*
o:transformer(
  $rules as item()*)
  as function(*)

Execute the extractor stylesheet and and attach the node handlers to the correct nodes as defined by the rules. TODO: rename as this is the real transforming function!!!

o:transformer(
  $rules as array(*)+,
  $options as map(*))
  as function(*)
o:tree-seq(
  $nodes as item()*)
  as item()*
o:tree-seq(
  $nodes as item()*,
  $children as function(*))
  as item()*
o:tree-seq(
  $nodes as item()*,
  $is-branch as function(*),
  $children as function(*))
  as item()*
o:unwrap() as function(item()*) as item()*

Create a node transformer that removes (unwraps) the outer element of all nodes that are elements. Other nodes are passed through unmodified.

o:unwrap(
  $node as array(*))
  as item()*

Unwraps all nodes that are elements.

o:wrap(
  $element as array(*)?)
  as function(*)
o:wrap(
  $nodes as item()*,
  $element as array(*)?)
  as item()*
o:xf-builder(
  $transformer as function(item()*) as item()*)
  as map(*)
o:xml(
  $nodes as item()*)
  as node()*

Converts mu-nodes to XML nodes with the default name resolver.

o:xml(
  $nodes as item()*,
  $builder as map(*))
  as node()*

Converts mu-nodes to XML nodes using a map of options. Currently it will only use the option 'ns' whose value must be a namespace map and 'qname' function that translates strings into QNames.

o:xslt(
  $stylesheet as item()*)
  as function(item()*) as item()*

Returns a node transformer that transforms nodes using an XSLT stylesheet.

o:xslt(
  $stylesheet as item()*,
  $params as map(*))
  as function(item()*) as item()*
o:xslt(
  $nodes as item()*,
  $stylesheet as item()*,
  $params as map(*))
  as item()*

Transform nodes using XSLT stylesheet.

o:xslt-builder(
  $rules as array(*)+,
  $options as map(*))
  as map(*)
⚠️ **GitHub.com Fallback** ⚠️