Counter and Theme Toggle - Xquery Typing CST Test
Loading…
Counter and Theme Toggle — Xquery Code
Demonstrates a simple counter with theme toggling using XQuery variables and functional expressions.
declare variable $count := 0;
declare variable $isDark := false;
declare function local:updateUI() {
concat('Counter: ', $count, '
', 'Theme: ', if ($isDark) then 'Dark' else 'Light')
};
declare function local:increment() {
declare variable $count := $count + 1;
local:updateUI()
};
declare function local:decrement() {
declare variable $count := $count - 1;
local:updateUI()
};
declare function local:reset() {
declare variable $count := 0;
local:updateUI()
};
declare function local:toggleTheme() {
declare variable $isDark := not($isDark);
local:updateUI()
};
(: Simulate actions :)
local:updateUI();
local:increment();
local:increment();
local:toggleTheme();
local:decrement();
local:reset();Xquery Language Guide
XQuery is a functional, expression-oriented language designed for querying, transforming, and manipulating XML data. It provides powerful tools for navigating hierarchical structures using XPath and is widely used in systems that store or exchange data in XML.
Primary Use Cases
- ▸Querying XML databases (e.g., BaseX, eXist-db, MarkLogic)
- ▸Transforming XML documents
- ▸Integrating heterogeneous data sources
- ▸Building APIs and services that output XML/JSON
- ▸Metadata processing and document-driven workflows
Notable Features
- ▸XPath-based navigation
- ▸Functional expressions and immutability
- ▸FLWOR expressions for structured querying
- ▸Native XML manipulation
- ▸Support for XML, JSON, and text output formats
Origin & Creator
Developed by the W3C XML Query Working Group in the early 2000s as a standard querying language for XML.
Industrial Note
XQuery is especially prominent in enterprise environments involving XML databases, digital publishing, content management, e-commerce feeds, and metadata-heavy systems.