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
3 answers

Recursive function returning boolean, with a for loop inside

My data is a binary tree, and will check through every child, returning true if it finds the data i want, if not, it keeps looking for it. In some way i want to return the variable @exists or something.. Well anyone might have a solution for my…
Johan
  • 11
  • 2
1
vote
3 answers

XQuery: Separate a sequence into multiple ones

I want to seperate a sequence into multiple ones. So e.g. I have this sequence let $allNumbers := (1,2,3,4,5) And I want as an result one sequence with all number less than 3 and one sequence with equal or more than 3. let $lessThanThree :=…
1
vote
1 answer

How to process multiple XPath or XQuery expressions in streaming mode efficiently

I need to evaluate multiple XPath (or possibly XQuery - I have some freedom to change the design here) expressions over a larger number of huge XML documents, potentially gigabyte size. If the files were small I could easily evaluate the expressions…
ewramner
  • 5,810
  • 2
  • 17
  • 33
1
vote
1 answer

XQuery - Fetch XML Value from SQL Server using XPath based on Condition

I have the following XML and you can see it contains three LevelA elements. I want to fetch /LevelA/Value (which is 9101) where /LevelA/LevelB2/LevelC == "Address". Now in PROD, the position of elements might change and so the address element might…
Varun Sharma
  • 2,591
  • 8
  • 45
  • 63
1
vote
1 answer

Marklogic XQuery detach all forests for a database

How to add a loop to list all the forests for a given database and detach all forests accordingly? xquery version "1.0-ml"; import module namespace admin = "http://marklogic.com/xdmp/admin" at "/MarkLogic/admin.xqy"; let $config :=…
CJ Chang
  • 325
  • 4
  • 12
1
vote
3 answers

Get Parent Value Using Nodes() and Value()

I have an XML document snippet that matches this XSD:
Yuck
  • 49,664
  • 13
  • 105
  • 135
1
vote
1 answer

Xquery get node with specific child element

I am using xquery 1.0 and have the following problem. My input message: correct hardcore
1
vote
1 answer

Qt XQuery Performance

I am considering using Qt for developing a new XML-based application that makes heavy use of XQuery. I am especially excited about the way QtXmlPatterns apparently lets you query any data with an appropriate model as if it were XML. I've used XML…
daveaglick
  • 3,600
  • 31
  • 45
1
vote
1 answer

XQUERY - how to get xml filename

I have a xml file $doc, I want to retrieve its file name so I use base-uri($doc) or document-uri($doc) with this result: "file:/C:/Users/Desktop/corpus/Decree.xml". How can I get just "Decree.xml"?
IL DOGE
  • 31
  • 3
1
vote
1 answer

xQuery return dynamic value if element is empty

I'm having the following request message: 2022 09 13
1
vote
1 answer

Parse, Update, Delete XML elements

I have the following sample XML and I am looking to Update: ShipToAddress1 to: test777 TestID to: 1234 where Sequence =1 20220619
vbgp
  • 73
  • 7
1
vote
1 answer

Parse, filter nested XML in TSQL

I have a table (table1) which has a column containing XML data. I need to parse that XML and create rows of data from the child elements of the element - The output needs to be something like TestID Sequence ParentSequence ExtID ExtName -1 …
vbgp
  • 73
  • 7
1
vote
1 answer

an XQuery query that calculates the average of the grades of each course

an XQuery query that calculates the average of the grades of each course, how i can do? Jack T
david9999
  • 19
  • 1
1
vote
1 answer

Custom sorting issue in MarkLogic?

xquery version "1.0-ml"; declare function local:sortit(){ for $i in ('a','e','f','b','d','c') order by $i return element Result{ element N{1}, element File{$i} } }; local:sortit() the above code is sample, I need the data…
anuj_gupta
  • 131
  • 4
1
vote
1 answer

How to put dynamic date filter in TDE?

In "context" how to use date function? I want to keep the triples only for last 10 days of the doc ingested in ML.