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

Get XML nodes from SQL Server column as comma-separated list

I have a data stored in a xml column and need a comma-separated list of child nodes. Using script below, I can only get "A B C". Please help me get "A,B,C" using xquery (Simple replace of space with comma does not help because we have data with…
Ben
  • 2,454
  • 26
  • 32
7
votes
1 answer

Translator using Antlr4

I want to create a translator from SQL to XQuery. I want to parse SQL and generate an intermediate structure and then use it to generate the XQuery query. (Note- I want to use an intermediate representation because i'm looking forward to translating…
Great
  • 95
  • 1
  • 4
7
votes
1 answer

Most efficient way to count occurrences in XQuery for multiple values

I have 1581 words that I need to look up in an XML corpus of Dutch (500 million words). This corpus itself is split up in many databases. (You can read why here.) We use BaseX as a server (version 7.9), which uses XQuery as input. I am interested in…
Bram Vanroy
  • 27,032
  • 24
  • 137
  • 239
7
votes
2 answers

Explain xpath and xquery in simple terms

I am new to programming. I know what XML is. Can anyone please explain in simple terms what xpath and xquery do Where are they used?
user421814
  • 585
  • 1
  • 6
  • 12
7
votes
1 answer

SQL Server XML Column exist() query

Assuming I have a SQL Server 2005 table with an xml column containing the following values: CREATE TABLE XmlTest ( XMLid int, Data xml) INSERT XMLTest VALUES ( 1 , '
doshea
  • 73
  • 1
  • 3
7
votes
2 answers

Howto refer dynamically to an XML file in XQuery in Saxon

I am using the XQuery processor Saxon. Now we write our XQuery in a ".xqy" file where we refer to the XML file on which we will perform our XQuery. Please see the example below: for $x in doc("books.xml")/books/book where $x/price>30 return…
Rahul ray
  • 191
  • 1
  • 4
  • 12
7
votes
2 answers

Regular Expressions in MarkLogic's xQuery

I am trying an XQuery using fn:matches with a regular expression, but the MarkLogic implementation of XQuery does not seem to allow hexidecimal character representations. The following gives me an "Invalid regular expression" error. (: Find text…
kalinma
  • 486
  • 5
  • 16
7
votes
1 answer

SQL Server : FOR XML sorting control by attribute

I am generating a XML file from a SQL Server query. I have some problem about sorting elements issues. For example, there is simple code as below. As you can see…
clear.choi
  • 835
  • 2
  • 6
  • 19
7
votes
1 answer

Drop the "fn:" in MarkLogic functions?

Is there a way with MarkLogic to not have to prefix every single fn: function with that prefix? I've seen lots of codes on the Internet that show me that I don't need it. Things can get rather verbose, you know? fn:not(fn:contains(...)), instead…
Mr Mikkél
  • 2,577
  • 4
  • 34
  • 52
7
votes
3 answers

How to insert xml into a node in another xml using XQuery?

I have two xml variable say @res, @student in a stored proc in SQL server 2005. @res contains English 67 Science 75 @student contains: XYZ
Himadri
  • 8,600
  • 15
  • 47
  • 70
7
votes
1 answer

Concatenating xml values when selecting by XQuery in T-SQL

This is my sample XML: value1 value2 And this is my test query: DECLARE…
sdds
  • 2,021
  • 2
  • 25
  • 33
7
votes
4 answers

Parse XML using T-SQL and XQUERY - Searching for specific values

I have some properties of an application being passed to me in XML form. I need to parse out the property by name and assign the value to the appropriate column in my database. I am currently parsing it out in a SSIS script component but it takes…
Dave L.
  • 87
  • 1
  • 2
  • 8
7
votes
2 answers

How do I Pivot on an XML column's attributes in T-SQL

I need to perform a pivot on an XML column in a table, where the XML contains multiple elements with a number of attributes. The attributes in each element is always the same, however the number of elements will vary. Let me give an…
Stephen Mesa
  • 4,769
  • 3
  • 23
  • 16
7
votes
3 answers

xQuery - count function

Im looking to form an xQuery which returns the category of a book if this category contains more than x amount of books. For example if I have 4 categories; music, film, education, health and they all have 1 book in, apart from music which has 3, im…
thrash
  • 187
  • 1
  • 4
  • 18
7
votes
2 answers

Shredding data from XML, Importing into Relational Tables (SQL Server 2008)

I have looked everywhere for help on this. I'm new to all this and I'm finding it hard to understand all the documentation on it. Say I have this XML: Liverpool
user1320771