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

Subtract 6 months date from the current date using Optic Query

I am trying to get last 6 months count of a column value based on a date field (Booking Created Date) using optic query in MarkLogic. With the below query , I am able to get the count of records when Booking date is less than the current date. What…
1
vote
1 answer

How to insert a xquery module in a Template file in MarkLogic

I have written one xquery to get count of my records based on some conditions and would like to put the result as a column value in a Template document. How can I call the xquery from the template in this case Below is the Xquery which calls all…
1
vote
1 answer

How to get count of a certain record with a specific value in MarkLogic xquery

I am trying to get count of a record for a given condition. Count the number of Ancillary Price in all documents in a collection where the Ancillary Price is greater than 1000. I am trying the below XQuery for that, it gives me this below…
1
vote
1 answer

XQuery function to use to connect and copy documents from one database to another in MarkLogic

What xquery functions I can use to connect with a MarkLogic database and copy the collection from that database to another database located in the same MarkLogic server.
1
vote
1 answer

XQuery uses a space separator when selecting AS [data()]

I've used an adaptation of shnugo's answer to Select all XML nodes from XML column , and this works a treat. However, the generated list has a space inserted between items. Is there a way to prevent the space separator from being included in the…
lukep
  • 111
  • 10
1
vote
1 answer

xQuery - Returning MAX Row

I'm pulling what hair I have left out! The resultset is all good but I now need to do something else. Here's the T-SQL SELECT documentdate , x.a.value('(Date)[1]','varchar(50)') as [Date] , x.a.value('(ReadCode)[1]','varchar(50)') as…
pee2pee
  • 3,619
  • 7
  • 52
  • 133
1
vote
1 answer

How to returns the text() of an xml value with a space between the nodes value?

In SQL Server 2008 R2, Considering the following xml DECLARE @xml xml = 'Chambre standardStandard room'; How can I return the following string: Chambre standard Standard room Currently, I'm only able to return the…
Pierre-Alain Vigeant
  • 22,635
  • 8
  • 65
  • 101
1
vote
1 answer

Remove a leaf node based on attribute value

I have this leaf structure and I Want to remove leafs that have attribute:d value="true".
mentor45
  • 17
  • 5
1
vote
1 answer

In cts:search using fn:doc() vs specific node in query

In below 2 queries how big the difference will be in performance. Option 1- cts:search(fn:doc(), cts:and-query(( cts:collection-query('xyz'), cts:element-value-query(xs:QName('test'),'12344') )) ) Option 2- specific…
anuj_gupta
  • 131
  • 4
1
vote
1 answer

How to lazily evaluate XQuery order by when the results are going to be a small subset anyway?

Imagine you have a large number of records inside an XQuery-based XML database:
Tom Morris
  • 3,979
  • 2
  • 25
  • 43
1
vote
1 answer

Rest vs XCC in MarkLogic

In Marklogic, do we have any preference over service call among REST API and XCC? Which is better for performance and why? Or which one is suitable in what scenario ? Assumption - Java layer is always present in the system.
anuj_gupta
  • 131
  • 4
1
vote
1 answer

How to extract multiple values from XML value column in SQL

I have a column with XML data as below 04/27/20220 How can I extract both Acc num and Suffix in SQL ? I want the result as Acc…
1
vote
1 answer

MarkLogic search query multiple duplicates, grab latest results based off timestamp field

I've got a dataset that looks like this: { "id": 1234, "name": "name-1", "timestamp: "2022-02-10T13:48:32.195344Z", } There are several thousand documents with unique id's in the database I'm trying to grab. However the…
Mike J
  • 149
  • 8
1
vote
1 answer

MarkLogic - false is true

let $d := doc('/test/a-false.json') return ($d, if ($d/a) then 'false is true' else 'false is false') The result: {"a":false} false is true Really? StackOverflow's robot was not contented with the above, so I will add some meaningless text that…
1
vote
1 answer

MarkLogic matches function with regular expression

I am new to XQuery so could you please help me to understand what is § and §.*$ in below MarkLogic XQuery: if (matches($cite, '§')) replace($cite,'§.*$','') here $cite := "HI CONST Preamble"
1 2 3
99
100