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

Does XQuery have exit statement for FLWOR expressions

I would like to know if xquery FLWOR expression has an exit statement like continue and break? For example I want to exit the for loop when a particular condition is reach.
Technocrat
  • 211
  • 2
  • 4
  • 11
6
votes
3 answers

TSQL: How can I update the value of an xml tag with the value of an xml tag from another related table?

How can I update the value of an xml tag with the value of an xml tag from another related table? something like this: UPDATE v2 SET [xml].modify ('replace value of (//TAG1/text())[1] with "CAST(v1.[xml].query(''//TAG2'') AS…
halfjust
  • 63
  • 1
  • 5
6
votes
1 answer

In SQL Server, deleting nodes using .modify() XQuery taking 38 minutes to execute

In SQL Server, I have a stored procedure with XML type temporary variable, and I am doing a delete operation on that variable. When I am running this stored procedure in my local VM which has 4 cores and 6 GB RAM, it takes 24 seconds to execute. But…
Rakesh
  • 73
  • 1
  • 9
6
votes
2 answers

Should cast of xs:double to xs:decimal be implemented as BigDecimal.valueOf(double) or new BigDecimal(double)?

XQuery, shared with XSLT and XPath 2.0 and later, supports various number data types, two of them are xs:double and xs:decimal. It is possible to cast an xs:double to an xs:decimal, as defined in…
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
6
votes
1 answer

Updating Oracle XMLType Column Content For a Given Value

I have a table, SECTION_ANSWER, in an Oracle 11g database which has an XMLType column. The XML is pretty simple, it follows the structure:
Green
The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80
6
votes
1 answer

Xquery distinct-values

I am getting my desired schema. But the one thing i need to do is to eliminate duplicate values. Hence I use distinct values, but what that function does is it displays all the values within one element. Input Schema:
user2272525
  • 137
  • 2
  • 11
6
votes
1 answer

XQuery data and text() function

Sorry even trying to watch tutorials I am just trying to understand the difference between the data() and the text() functions in XQuery. Any clarification is appreciated.
TheWommies
  • 4,922
  • 11
  • 61
  • 79
6
votes
2 answers

FLWOR in Sql server count number of hits

I am using SQL Server 2008 R2. My problem is that I want to count number of hits that i receive from XQuery query using FLWOR. For each hit, I want a consecutive number, like: 0,1,2,3,4... My query: select @xml.query('for $s at $count in…
FrenkyB
  • 6,625
  • 14
  • 67
  • 114
6
votes
3 answers

how do I select records that are like some string for any column in a table?

I know that I can search for a term in one column in a table in t-sql by using like %termToFind%. And I know I can get all columns in a table with this: SELECT * FROM MyDataBaseName.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME =…
bernie2436
  • 22,841
  • 49
  • 151
  • 244
6
votes
1 answer

SQL Server XQuery with Default Namespace

I've got some XML Data in a SQL Server Table in an XML Column as follows: IndividualMatch
reach4thelasers
  • 26,181
  • 22
  • 92
  • 123
6
votes
4 answers

How to insert/replace XML tag in XmlDocument?

I have a XmlDocument in java, created with the Weblogic XmlDocument parser. I want to replace the content of a tag in this XMLDocument with my own data, or insert the tag if it isn't there. mfkdslmlfkm
svrist
  • 7,042
  • 7
  • 44
  • 67
6
votes
3 answers

SQL Server xml string parsing in varchar field

I have a varchar column in a table that is used to store xml data. Yeah I know there is an xml data type that I should be using, but I think this was set up before the xml data type was available so a varchar is what I have to use for now. :) The…
Dusty
  • 4,667
  • 3
  • 29
  • 35
6
votes
1 answer

Complicated application stack refactor/redesign strategies

I am involved in a project maintenance plan that involves either major refactoring or complete redesign. We have a very complicated existing technology stack that has evolved organically over a period of five years. I myself joined on three years…
topmulch
  • 240
  • 3
  • 15
6
votes
1 answer

Retrieve an element without sub-elements in SQL Server

I am using SQL Server 2008 and I want to retrieve XML elements and return the element itself and its attributes without any sub elements and without the text(). Eg the following XML has 4 nodes (doc, apple, b, banana):
Ubercoder
  • 711
  • 8
  • 24
6
votes
2 answers

xquery- getting count of those elements, within a single parent, which are not empty

Please consider the following XML--

Text sihdfaif

Text sihdfaif

Text sihdfaif

Text sihdfaif

Text sihdfaif

Now, I want to obtain the number of p…
Arvind
  • 6,404
  • 20
  • 94
  • 143