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

How to use XQuery to output json using Saxon from Java

I'm using XQuery to convert the XML document below to JSON, using Saxon to process the XQuery file. Book1AuthorSurname, Book1AuthorFirstname Book1 Title
Joseph McCarthy
  • 897
  • 2
  • 19
  • 41
6
votes
1 answer

Xquery: same test has different result whether used in switch/case or in if/then/else

I can't find an explanation on the following. I've made this test script in order to solve my previous question. xquery version "3.0" ; declare default function namespace 'local' ; declare function local:is-img-only( $element as element() ) as…
laconis
  • 97
  • 8
6
votes
1 answer

Receive XDMP-LOCKED error when no locks exist

I have a function that I wrote for generation of a sequential number. The function is as follows: declare function generate-instrument-Id( $cnt as xs:int? ) as xs:int { let $count := if( $cnt and $cnt > 0 ) then $cnt else 1 let $url :=…
Kemal Erdogan
  • 1,060
  • 1
  • 9
  • 19
6
votes
2 answers

Insert child nodes from an SQL xml variable into another xml variable

I have two xml variables: @main xml = '' @insert xml = 'SomeRow' And I would like to insert child nodes of @insert rows, so that I have a resultant XML that looks like this:
Vinnie Amir
  • 557
  • 5
  • 10
6
votes
1 answer

Invalid Value Operator '<'(less than)sign when passed as -query_filter in MLCP

I am using MLCP(Marklogic Content Pump) for copying content from one database to another. In this i'm using -query_filter option and its value is a cts:query in XML serialized format of a set of cts:element-range-query wrapped in cts:and-query :…
6
votes
4 answers

xquery word wrap

I need to word wrap long string to 100 characters using XQuery. In other words, to change some spaces to newlines so that the non-patological lines will be shorter than 100 characters. Is there an easy way?
danatel
  • 4,844
  • 11
  • 48
  • 62
6
votes
2 answers

MarkLogic cts:element-query false positives?

Given this document :- T1V1 T2V2 unsurprisingly, I find that this will pull back the page in a cts:uris() :- cts:and-query(( …
Andy Key
  • 125
  • 5
6
votes
1 answer

How do I programmatically create JSON in XQuery in MarkLogic?

I need to build up a JSON node in XQuery in MarkLogic. I know that I can use xdmp:unquote() to parse from a string into a node(). However, I’d like to build the JSON programmatically, without ugly string concatenation. I can use computed element…
Justin Makeig
  • 2,097
  • 15
  • 29
6
votes
4 answers

How to get list of document uri names from a database marklogic?

Hey I am trying to get the list of all document names /uri from a given MarkLogic database. I found this line in stackoverflow: How to get total number of documents in Marklogic database? ...which will get the count of documents in a database. I'm…
happybayes
  • 321
  • 4
  • 12
6
votes
1 answer

marklogic invoke function with parameters

In the documentation for xdmp:invoke, it's possible to pass parameters as the second argument. For xdmp:invoke-function this option is not available. Is there any workaround to achieve this? Mapping a list to a function is easy. What I am trying…
chriskelly
  • 7,526
  • 3
  • 32
  • 50
6
votes
2 answers

SQL Server: how to remove leading 'A's from base64 string

I'm working on SQL Server and trying to create a single key combining data from bigint and string columns. To minimize the size of bigint's represented as strings I'm using Base 64 encoding. The problem is that the result includes leading 'A's…
Viacheslav Nefedov
  • 2,259
  • 3
  • 15
  • 15
6
votes
1 answer

Improve Xquery performance in SQL Server

I have an Azure SQL Database with 1 table and a lot of records (more than 75 000). The table contains a column of the XML datatype. This column looks like this:
A. Meheus
  • 167
  • 1
  • 9
6
votes
1 answer

xquery insert node from external xs:string variable (basex)

I am attempting to insert new elements into an xml document using BaseX. declare variable $part external; insert nodes $part as first into db:open("PARTDB")/assembly[@name="ZB09010"] I am using the BaseX GUI for my testing and have defined the…
mikee
  • 335
  • 3
  • 11
6
votes
1 answer

Getting the following sibling in an XPath when "following" axis is not supported

I am trying to get the text elements of a table that follows a paragraph that contains a specific text element using XQuery on MS SQL Server. The problem is whenever I use the axes "following", "following-sibling" or "previous-sibling", I get an…
TimeHorse
  • 510
  • 3
  • 14
6
votes
3 answers

Embedding XQuery in Java

I need to retrieve some details from a MusicXML (xml) file in Java. I managed to read xml files in java - but through a web service (where I have to be online, connected to internet when I'm running my code). I came across XQuery where you can…
Dolphin
  • 375
  • 2
  • 8
  • 16