Questions tagged [xquery]

XQuery is a functional language designed to query and manipulate XML data. It is a superset of XPath, to which it adds features such as the creation of new nodes and more powerful FLWOR expressions. Although it shares its data model with XSLT, XQuery is optimized for querying rather than transforming data, and as such it has a different design inspired by SQL.

W3C XML Query

XQuery has a rich set of features that allow many different types of operations on data and documents, including:

  • Selecting information based on specific criteria
  • Filtering out unwanted information
  • Updates
  • Searching for information within a document or set of documents
  • Joining data from multiple documents or collections of documents
  • Sorting, grouping, and aggregating data
  • Transforming and restructuring XML data into another XML vocabulary
    or structure
  • Performing arithmetic calculations on numbers and dates
  • Manipulating strings to reformat text

XQuery can be used not just to extract sections of XML documents, but also to manipulate and transform the results.

Modified from O'Reilly XQUERY ISBN-10: 0-596-00634-9 By Priscilla Walmsley.

Relationship to XSLT

XQuery has a large overlap with in terms of purpose but has a syntax and model inspired largely by . Most built in functions are shared with XSLT.

Relationship to XPath

XQuery is mostly a superset of . XQuery version 1 is based on XPath version 2. XQuery version 3 is based on XPath version 3. Version 2 was skipped in order to align the XQuery and XPath version numbers. XQuery 3.1 like XPath 3.1 supports JSON processing through the new map and array types and JSON <--> XML conversion using the xml-to-json and json-to-xml functions as well as parse-json and json-doc functions.

Implementations

  • A list of the current implementations according to the W3C XML Query group.
  • Version 9.8 and later of the Saxon processor support both XSLT 3.0 and XQuery 3.1.
  • BaseX implements all versions of the language and can be use through a CLI.

References

Online training

Books

5333 questions
1
vote
1 answer

XML flatten multiple hierarchical nodes SQL Server 2016

I have a hierarchical XML structure that I need to flatten down to a simple list of XML elements. This is the code I've tried so far: DECLARE @XmlString XML = CONVERT(XML, '1123test addtest…
Anito1989
  • 13
  • 3
1
vote
1 answer
1
vote
0 answers

Is there a method (or even dirty hack) to move QXmlQuery instance to another thread to evaluate xpath without assertion?

I need to evaluate a lot of prepared xqueries against a stream of XMLs, since QXmlQuery instances created at startup, copying or moving them to the thread causes an assertion failure. At this point i solve this by creating an instance of QXmlQuery…
tomato
  • 13
  • 2
1
vote
1 answer

cts:search pass the node dynamically

Is there a way to have the below code working? let $node := 'childnode' return cts:search(/root/$node, cts:and-query(( cts:collection-query('collection') )) )
anuj_gupta
  • 131
  • 4
1
vote
1 answer

SQL / XPATH - How to select all possible elements that have the same name into separate rows/columns

I need to select all the elements under a specific node, all the elements have the same name. Tables Lets say I have 2 tables in my database; [Access_Groups], This table contains all the groups that can access my application [User_Accounts], This…
user19570763
1
vote
1 answer

XQuery on doc collection with multiple prefixes that map to the same namespace

I am using XQuery (Berkeley dbXML 6.0) to query documents from a collection. All documents use the same namespace, but the prefixes differ. To abstract the problem: doc1: here i am doc2:
Marie R
  • 270
  • 3
  • 9
1
vote
2 answers

Get and update XML value with a certain attribute

I have a SQL table with an xml column that has values like this, across multiple rows: Foo 1 M 2020-01-01
mariocatch
  • 8,305
  • 8
  • 50
  • 71
1
vote
1 answer

Extracting complex nested XML into a structured table

I have the following in a SQL Server varchar column (so, have to CAST AS XML I guess):
tbone
  • 5,715
  • 20
  • 87
  • 134
1
vote
1 answer

How to sort by dynamically with ascending or descending in Marklogic?

let $sortelement := 'Salary' let $sortby := 'ascending' for $doc in collection('employee') order by $doc/*[local-name() eq $sortelement] $sortby return $doc This code throws and error, what is the correct way to do this?
anuj_gupta
  • 131
  • 4
1
vote
1 answer

How can we delete the source contents from source database after copying them to another database in MarkLogic

I am using below xquery to copy documents from one database to another in MarkLogic. Along with copying my requirement is to remove those documents which are successfully copied. I cannot remove the collection fully as some of the documents may not…
1
vote
1 answer

Error in Optic query in MarkLogic - Invalid coercion: map:map

I am getting an invalid map error when trying to get the percentage of a record based on a certain condition to the total count of another record. Can you please help to identify the issue here in my code. The below code is trying to get the…
1
vote
2 answers

Create XML nodes for values in SQL

I'm having an issue to create XML nodes. Help is much appreciated ! This is a sample code declare @tbl as table ( employeeName nvarchar(50), payFrequency nvarchar(50) ) insert into @tbl select 'John', 'Monthly' union select 'Carl',…
1
vote
1 answer

Error in MarkLogic Optic Query - to get percentage of occurrence of a record in a template view document

I am trying to find the percentage of a certain record based on a condition to the total no of that record . I am using optic query to get the result. To be specific on the requirement : Give a percentage of a certain record, when there is a…
1
vote
1 answer

Declare column in variable is not working in Optic query MarkLogic

I am trying to declare the column in a variable and want to call that variable inside my program. Here is my optic query code which returns me - Column not found. Please help to understand the problem in my query. xquery version "1.0-ml"; import…
1
vote
1 answer

Copy documents from one database to another in MarkLogic - xdmp:document-insert Failing

I am using the below code to copy documents from one database to another database in MarkLogic. But I am getting error - arg2 is not of type node() The xquery I am trying - xquery version "1.0-ml"; for $doc in cts:search(doc(),…
1 2 3
99
100