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
1
vote
2 answers

Creating dynamic XML tag names for output from SQL

(This is a follow on to Manipulating tag names and output structure in SQL which was well answered by Yitzhak Khabinsky) I am trying to extract data from Microsoft SQL Server 2016 in specific XML formats. I can get close with standard FOR XML…
AA23ds
  • 17
  • 5
1
vote
4 answers

xQuery substring problem

I now have a full path for a file as a string like: "/db/Liebherr/Content_Repository/Techpubs/Topics/HyraulicPowerDistribution/Released/TRN_282C_HYD_MOD_1_Drive_Shaft_Rev000.xml" However, now I need to take out only the folder path, so it will…
Kevin
  • 6,711
  • 16
  • 60
  • 107
1
vote
1 answer

How to create custom REST endpoint via mlgradle?

I want to create custom REST endpoint in MarkLogic, like "http://localhost:port/v1/resources/my_custom_endpoint" And I am doing it via curl command in my local. But I want to integrate this with ml-gradle to automate this process as first install…
anuj_gupta
  • 131
  • 4
1
vote
1 answer

unexpected character found in xquery code

I am trying to run the following in my query console. xquery version "1.0-ml"; import module namespace functx = "http://www.functx.com" at "/MarkLogic/functx/functx- 1.0-nodoc-2007-01.xqy"; let $forestNames :=…
Aviator
  • 543
  • 1
  • 4
  • 10
1
vote
1 answer

passing xpath to xquery

I usually hardwire the xpath in the xqueries like so: let $xml := abc return $xml/book/name I am trying to figure out if there is a way to path xpath as a string variable and use it in…
sony
  • 1,557
  • 10
  • 36
  • 50
1
vote
3 answers

Using T-SQL Xquery to extract data from XML with low-ascii represented like "&#x1E"? Or just use T-SQL?

I have strings inside XML that contain low-order ASCII. Specifically, the EDI contains special characters like char(28), char(29), char(30) (aka File Separator/Group Separator/Record Separator). The way the devs encode it in the XML string, these…
mbourgon
  • 1,286
  • 2
  • 17
  • 35
1
vote
2 answers

Deleting multiple nodes from XML with XQuery

I have XML that looks something like that: <1> <2> <3> <3> <3> <2> <3> <3> I need to always have only one '3' element in each '2' so I need to delete additional ones with…
idix
  • 25
  • 4
1
vote
1 answer

Send HTTP Request from local server to remote server

I am using BaseX version 9.5, I am trying to send HTTP request from local to remote server to read database, but not getting the response. let $server := 'http://10.102.xxx.xxx:8984/rest/' let $sendreq := (http:send-request( …
1
vote
1 answer

Breaking up a sequence of id numbers using tokenize

I have an XML file that looks like this:
1
vote
1 answer

Best way to handle and deploy XQuery stored procedures?

Is there a tool for deploying things into exist? if I've got a bundle of, say, schemas and XQuery stored procedures? Is there a way of, say, bundling those into a zip or tar file and uploading them or deploying them into eXist? Alternatively what is…
Tom Morris
  • 3,979
  • 2
  • 25
  • 43
1
vote
1 answer

T-SQL combine based on values with for XML path

I am running stuck in something I can't get my head around. I have some mock-up data to simulate: DECLARE @tbl TABLE (orderReference VARCHAR(50), shipmentReference VARCHAR(50), additionalComments VARCHAR(200)) DECLARE @finalXML XML INSERT INTO…
forRJ
  • 70
  • 6
1
vote
1 answer

Using JSON with XQuery page

So I am using a jQuery plugin (jsonp) to make a cross-domain call to an api and getting JSON data back. I need to somehow get this data into my XQuery page. I'm using Marklogic server to store all my XML data and I know it has some XDMP functions…
bjo
  • 550
  • 2
  • 8
  • 15
1
vote
1 answer

Convert child nodes into a single string using XQuery in ML 10

We have an application whose backend ML response format is JSON and we have a element with both text and nodes as below. Header <bold>abc</bold> Now, while converting the above node to JSON, we get the output as "Title": {"bold":…
Antony
  • 183
  • 8
1
vote
2 answers

How to use the collection()-function with saxonche

I am trying to use the collection()-function using the new saxonche-Python-Module (https://pypi.org/project/saxonche/). I would expect, that it returns all XML-documents inside the current directory. Instead it just returns None. My code looks…
B Polit
  • 162
  • 8
1
vote
2 answers

Openxml select data from complex xml having prefix

The XML structure and expected result is below, I can loop through all the data but unable to pick xml elements from xpath as the item node is prefixed with "a:" I have tried following but none is working: #1: Set @path = …
Bilal Siddiqui
  • 3,579
  • 1
  • 13
  • 20