xsql
Language

Language Overview

Scripts, blocks, comments, and how USE scopes them.

Scripts and blocks

A script is a sequence of blocks. Each block has a source — the document it operates on, set by USE — and a list of verbs (SELECT, FOREACH, SET, DELETE, REPLACE, INSERT, MERGE, or one of the MySQL-style shorthands).

; USE is sticky: it applies to every following block until the next USE.
USE database.local.xml

FOREACH arm IN arms
    DELETE IGNORE arm.unlock_civi_science
;

; still database.local.xmlUSE wasn't repeated
SELECT GROUP arms;

USE <path> selects a file on disk. USE "path" works the same, for paths that need quoting. USE INPUT selects the XML document piped in on stdin (see CLI: filter mode).

Statement termination and comments

; terminates a statement block, and everything after ; on that line is ignored — so a line starting with ; doubles as a comment:

; this whole line is a comment
SELECT GROUP goods;   this trailing text is also ignored

Groups vs. tags

Most verbs act on either a group or a tag — this distinction shows up everywhere, so it's worth internalizing early:

  • A group is the first element whose tag, or name/id attribute, equals the given name. GROUP goods matches one container element and the verb operates on (usually iterates) its direct children.
  • A tag (TAG t) matches every element whose tag equals t, at any depth, regardless of attributes. Use it for documents that have no reliable group/container structure.

See Group vs. Tag for the full comparison, including how nested FOREACH ... IN TAG differs from a top-level one.

Next

On this page