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
8
votes
1 answer

Passing XQuery xml element as external variable to Marklogic via XCC

We have a fairly simple XQuery and Groovy code as follows. Xquery code : declare variable $criteria as element(criteria) external ; { $criteria/equals/field } Here is the test code that is trying to…
Irina Muchnik
  • 93
  • 1
  • 4
8
votes
2 answers

XMLAGG with RTRIM issue

Currently I have the following query: SELECT CASE WHEN ('[Param.3]' = 'SELECTED') THEN (SELECT RTRIM(XMLELEMENT("Rowset", XMLAGG(RW.R ORDER BY RW."ID")), ' ' ) AS Orders FROM TMTABLE UL,…
Soham Shah
  • 561
  • 2
  • 8
  • 35
8
votes
3 answers

How to Generate an XML File from a set of XPath Expressions?

I want to be able to generate a complete XML file, given a set of XPath mappings. The input could specified in two mappings: (1) One which lists the XPath expressions and values; and (2) the other which defines the appropriate…
Larry
  • 11,439
  • 15
  • 61
  • 84
7
votes
2 answers

Merging XML in an SQL Server

Let's say I have the following two pieces of XML in my database xml 1 a value xml 1 b value xml 1 c value
MrEyes
  • 13,059
  • 10
  • 48
  • 68
7
votes
2 answers

Using SQL Server 2005's XQuery select all nodes with a specific attribute value, or with that attribute missing

Update: giving a much more thorough example. The first two solutions offered were right along the lines of what I was trying to say not to do. I can't know location, it needs to be able to look at the whole document tree. So a solution along these…
phloopy
  • 5,563
  • 4
  • 26
  • 37
7
votes
2 answers

Limit number of results in xquery

I have the following Xquery code: for $w in $words let $freq := (count($corpus[. eq $w]) div count($content2[text() eq $w])) order by $freq descending return {$w}{$freq} $words is some distinct words that appears (may…
Ataman
  • 2,530
  • 3
  • 22
  • 34
7
votes
7 answers

How XQuery is actually used?

I have been reading a lot of XQuery tutorials on the website. Almost all of them are teaching me XQuery syntax. Let's say I have understood the XQuery syntax, how am I going to actually implement XQuery on my website? For example, I have…
Poh
7
votes
1 answer

Is there an equivalent to SQL's IN clause in XQuery?

Is there anything like the SQL IN clause in XQuery? E.g., I want to do something like this: where $x/lotClosedYn in ('Y','N') using IN keyword is giving an error, I am using saxon for XQuery processing.
SnoopyMe
  • 1,015
  • 1
  • 12
  • 21
7
votes
4 answers

Extracting child node values with QXmlItem as a QXmlQuery focus

I've been trying to fetch node text values from this XML file: 1 tytuł 21 5
TY
C.TY
2
Janek Królikowski
  • 1,101
  • 1
  • 9
  • 10
7
votes
1 answer

What does the operator "=>" in XQuery do?

When I look up XQuery examples i sometimes see the operator =>used. I tried searching for the meaning of it, but could not find anything. Since i am using MarkLogic, it is possible that it is only for MarkLogic, but i doubt that. From the examples i…
7
votes
1 answer

Java error: Unable to initialize main class

I am trying to run this code but I get the following error. package practicaXML; import javax.xml.xquery.*; import org.w3c.dom.Node; import net.xqj.basex.BaseXXQDataSource; public class App { public static void main(String[] args) { try…
winter
  • 207
  • 1
  • 4
  • 13
7
votes
4 answers

XQuery counters inside a for

Let's say I have the XQuery code below: for $y in doc("file.xml")/A/B for $x in $y/C where $x/constraint1 != "-" and $x/constraint2 > 2.00 do stuff Can I use a counter, to count how many my code will enter inside the second…
jong
  • 71
  • 1
  • 1
  • 2
7
votes
1 answer

How to get all namespace declarations of a single XML element

How can I use XPath query (or even XQuery) to get nampespace prefix declaration of a single element? I want to check if they get defined on more than 1 place. For example, for the first element, it would be xmlns and xmlns:n, for the second only…
ivanacorovic
  • 2,669
  • 4
  • 30
  • 46
7
votes
4 answers

Unit Testing XQuery

I've been working with a document repository using XQuery (via Java and .NET interfaces) and was wondering if anyone has any recommendations for unit testing XQuery modules?
toddk
  • 873
  • 1
  • 11
  • 20
7
votes
1 answer

xQuery LIKE-operator?

Is there any way to perform a LIKE operation with XQuery in the same way as with SQL? I wan't to construct some "startswith", "endswith" and "contains"-expressions. Example of what I want to achieve: for $x in /user where $x/firstname LIKE '%xxx'…
jorgen.ringen
  • 1,285
  • 5
  • 14
  • 20