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
9
votes
2 answers

Inserting a child node in an XMLTYPE column

I have a simple query: WITH xtbl AS ( SELECT XMLTYPE ('1') AS xcol FROM DUAL ) SELECT XMLQUERY ('copy $tmp := . modify insert node 2 into $tmp/a/b …
Rachcha
  • 8,486
  • 8
  • 48
  • 70
9
votes
1 answer

Xquery to concatenate

for the below data - let $x := "Yahooooo !!!! Select one number - " let $y := 1 2 3 4 5 6 7 I want to get the output as - `Yahooooo !!!! Select one number - [1 or 2 or 3 or 4…
John
  • 2,820
  • 3
  • 30
  • 50
9
votes
4 answers

XQuery: how to properly append , in for loop

So I have xml data like this: 213-512-7457 213-512-7465 and with this XQuery: { for $phone in $c//PhoneNumber let $phoneStr := "" return concat($phoneStr, $phone)…
sivabudh
  • 31,807
  • 63
  • 162
  • 228
9
votes
2 answers

Select XML element in SQL Server

I have some XML that I need to parse using SQL Server 2008. I think I'm close to getting what I want, but I don't have the correct syntax (I believe). I have the following: DECLARE @doc XML SET @doc = '
jared
  • 1,344
  • 4
  • 20
  • 38
9
votes
4 answers

Can I declare a global variable in xquery in Marklogic Server?

I want a global variable which I can use in my different .xqy pages. Can I declare such a variable in xquery in Marklogic Server ?
Puneet Pant
  • 918
  • 12
  • 37
8
votes
4 answers

XQuery/XPath: Using count() and max() function for return of element with highest count

I have an XML file that contains authors and editors.
Jea
  • 484
  • 2
  • 5
  • 17
8
votes
4 answers

How to suppress indentation for XML output in XQuery

Is there a way from within an XQuery to remove indentation of the XML output? Eg. say I had an XQuery of; producing an XML result document of; How can I remove the indents so the output document looked like…
Nigel Alderton
  • 2,265
  • 2
  • 24
  • 55
8
votes
3 answers

XQuery multiple xml files?

Is it possible to open 2 documents from an xQuery and do a join on them?
Ryu
  • 8,641
  • 10
  • 65
  • 98
8
votes
4 answers

Running XQuery on the command line

It sounds like I need some type of XML processor It looks like theres a program called Saxon which I can use to run XQuery When I try this websites example I get Error: Could not find or load main class net.sf.saxon.Query I don't know how to set…
Sam
  • 1,765
  • 11
  • 82
  • 176
8
votes
5 answers

Updating variables in XQuery - possible or not?

I'm a little bit confused concerning variable updates in XQuery: On [1] it says: Variables can't be updated. This means you can't write something like let $x := $x+1. This rule might seem very strange if you're expecting XQuery to behave in the…
stefan.at.kotlin
  • 15,347
  • 38
  • 147
  • 270
8
votes
3 answers

Getting cdata content while parsing xml file

I have an xml file You can use HTML and CSS
Warrior
  • 5,168
  • 12
  • 60
  • 87
8
votes
1 answer

Using XQUERY/Modify to replace a piece of my XML with value from varchar field

I have a table: MyTable config as XML title as varchar(255) In MyTable.config I have XML in the following structure:
Jason
  • 16,739
  • 23
  • 87
  • 137
8
votes
3 answers

Regex anchors inside character class

Is it possible to use anchors inside a character class? This doesn't work: analyze-string('abcd', '[\s^]abcd[\s$]') It looks like ^ and $ are treated as literal when inside a character class; however, escaping them (\^, \$) doesn't work either.…
wst
  • 11,681
  • 1
  • 24
  • 39
8
votes
2 answers

avoiding XDMP-EXPNTREECACHEFULL and loading document

I am using marklogic 4 and I have some 15000 documents (each of around 10 KB). I want to load the entire content as a document ( and convert the total documents to a single csv file and output to HTTP output stream for downloading). While I load the…
Ranjan Sarma
  • 1,565
  • 5
  • 22
  • 36
8
votes
1 answer

XQuery - group by and count

John
  • 2,820
  • 3
  • 30
  • 50