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

XPath - compound predicate + test if value does NOT start with something

I need help with some XPath. Say I am working on XHTML. How do I select all the a elements whose href attribute is NOT empty and does not begin with, say, 'mailto:'?
StackOverflowNewbie
  • 39,403
  • 111
  • 277
  • 441
13
votes
2 answers

XQuery: Create a new element with a given name?

I have data like: USERID NAME RATING I want to transform it into: How can I do this?
Nick Heiner
  • 119,074
  • 188
  • 476
  • 699
13
votes
8 answers

Execute a XQuery with PHP

How to execute a XQuery in PHP? Can you give me an example? Thank you.
abernier
  • 27,030
  • 20
  • 83
  • 114
13
votes
2 answers

xquery filter on attribute and element

I have the following simple XML document: Volvo 855
general exception
  • 4,202
  • 9
  • 54
  • 82
13
votes
7 answers

Updating counter in XQuery

I want to create a counter in xquery. My initial attempt looked like the following: let $count := 0 for $prod in $collection let $count := $count + 1 return {$count } Expected result: 1 2
Gopal Thakur
  • 227
  • 1
  • 2
  • 5
12
votes
4 answers

XPath / XQuery: find text in a node, but ignoring content of specific descendant elements

I am trying to find a way to search for a string within nodes, but excluding ythe content of some subelements of those nodes. Plain and simple, I want to search for a string in paragraphs of a text, excluding the footnotes which are children…
Hemka
  • 123
  • 1
  • 1
  • 4
12
votes
2 answers

Xquery get value from attribute

I have some xml and need to extract values using sql 0 1 I need to get…
Steven
  • 2,148
  • 8
  • 33
  • 50
12
votes
1 answer

How to get count of childnodes in XML file using XQuery

I want to get or return the number of item() in an xml file using the XQUERY. Is there an easy way to do that in XQuery? Here is my sample XML data:
napstyr maceda
  • 179
  • 3
  • 13
12
votes
3 answers

Getting multiple records from xml column with value() in SQL Server

This SQL only returns the first Activity element. How do I select them all? If I remove the [1] in the query I get an error that "value() requires a singleton". DECLARE @myDoc xml SET @myDoc = '
Graeme
  • 2,597
  • 8
  • 37
  • 50
12
votes
3 answers

Use of xml.modify to insert parameters into specific element of an xml column

I would like to use a stored procedure to insert some values passed in as parameters into elements in the xml of a column. I have this so far The following parameters: @profile_id int, @user_id nvarchar(50), @activity_name…
Christian
  • 1,685
  • 9
  • 28
  • 48
11
votes
3 answers

XQuery in SQL server doing SUM over zero value

I'm trying to extract monetary sums stored in some poorly formated xml columns (there is no schema defined for the XML column which I guess is part of the problem). I'm getting a conversion error whenever I encounter a node with 0 as its…
Vegar Westerlund
  • 1,604
  • 3
  • 16
  • 24
11
votes
3 answers

Is there any way in XQuery to get the current time in milliseconds since some Epoch?

XQuery offers various date/time functions like current-dateTime(), however I can't seem to find one which gives me the time in milliseconds since Epoch. Functions to extract hours, minutes and seconds seem to exist too individually. What is the…
jbx
  • 21,365
  • 18
  • 90
  • 144
11
votes
3 answers

Updating Xml attributes with new values in a SQL Server 2008 table

I have a table in SQL Server 2008 that it has some columns. One of these columns is in Xml format and I want to update some attributes. For example my Xml column's name is XmlText and it's value in 5 first rows is such as:
SMD
  • 333
  • 1
  • 2
  • 10
11
votes
5 answers

XQuery while using distinct-values()

XML File
user1388575
10
votes
2 answers

What are the differences between JSONiq and XQuery 3.1?

Both JSONiq and XQuery 3.1 extend XQuery 3.0 with support for JSON. How do they differ?
Ghislain Fourny
  • 6,971
  • 1
  • 30
  • 37