FAQ Database Discussion Community


From XQuery to XHTML

xml,xhtml,xquery
I would need some help. I'm trying to write an XQuery, whose output would be an XHTML file. The problem is, that "An XHTML document must have an XHTML DOCTYPE declaration" and I'm unable to put the DOCTYPE line in my XQuery file to generate a valid XHTML file. I...

Clean and convert HTML to XML for BaseX

html,xml,converter,xquery,basex
I would like to run some XQuery commands using BaseX over an HTML source that may be full of <script>, <style> nodes that must be removed and also unclosed tags (<br>, <img>) that must have a pair. (for example the dirty source of this page ) "Converting HTML to XML"...

XQuery retrieval of a value

sql,sql-server,xml,xquery
I have the following T-SQL that determines if a row exists using two criteria: Declare @x xml = ' <row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="page" itemValue="Confirmation" itemType="string" /> <row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="visited" itemValue="false" itemType="bool" />' SELECT @x.exist('/row[@Node eq "root.local.navigation[7]"] and /row[@itemValue eq "Confirmation"]') Question: Given the above SELECT, how can...

Difference between importing and declaring module namespace in XQuery?

xquery
What is the difference between the following: import module namespace fs = "http://expath.org/ns/file"; declare namespace an = "http://zorba.io/annotations"; How does "import module namespace" compare to "declare namespace"? And more over, with namespace decalaration waht is the difference between declare namespace an = "http://zorba.io/annotations"; and module namespace an = "http://zorba.io/annotations"; ...

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

sql-server,xml,xquery
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 when...

XQuery: Return how many times a search term was found in a XML document

xml,xquery,exist-db
I have a collection of two XML files (tagged according to TEI standard and containing lots of <entry> elements) in an eXist database. I'm looping through the file with a FLWOR routine, looking for the search term the user typed in a form ($searchterm) and returning the contents of certain...

Sum the values when siblings nodes are repeated in XQuery

xquery
I have a sequence of nested nodes and I'm attempting to find the repeated dates (considering only year and month) of the due_date nodes in each loan and then sum the values of their sibling nodes (amount). An example explains better. File payments.xml: <loan> <id>1</id> <payments> <local_payment> <due_date>2012-11-28T08:00:00Z</due_date> <amount>484</amount> </local_payment>...

How to find the lowest common ancestor of two nodes in XQuery?

xquery,basex
Suppose the input XML is <root> <entry> <title>Test</title> <author>Me</author> </entry> </root> I would like to find the lowest common ancestor of title and author. I tried the following code in BaseX: let $p := doc('t.xq')//title, $q := doc('t.xq')//author, $cla := ($p/ancestor-or-self::node() intersect $q/ancestor-or-self::node()) return $cla But it returns nothing (blank...

XQuery UNION of multiple criteria

sql,xml,xquery
How do you code in XQuery (SQL Server 2012) to do an .exist with multiple criteria? Declare @x xml = ' <row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="page" itemValue="Confirmation" itemType="string" /> <row ParentID="45" ObjectID="0" Node="root.local.navigation[7]" itemKey="visited" itemValue="false" itemType="bool" />' -- These work fine SELECT @x.exist('/row[@Node eq "root.local.navigation[7]"]') SELECT @x.exist('/row[@itemValue eq "Confirmation"]') But...

XQuery/XPath LIMIT a sum

xpath,xquery,xpath-2.0,xquery-3.0
I am new to XQuery. I need to limit by 1 in XQuery but I'm having trouble. I am trying to find out the winner of a tournament by finding each players scores and summing up the scores to get the total scores. I then sort in descending order and...

Count consecutive repetitive element in a sequence using XQuery

xpath,functional-programming,integration,xquery,osb
If the Sequence = [a a b c c c a d d e e e f g h h] then the Output = [1 2 1 1 2 3 1 1 2 1 2 3 1 1 1 2] Have tried to use recursion but no luck...Please Help..Thanks in...

BaseX XQuery error: root(): no context value bound

xpath,xquery,grouping,basex
I am trying to run the following XQuery expression in BaseX to extract elements between two succeeding headings. (as an article section). xquery for $x in doc("test.xq")//h2, $y in $x/following-sibling::h2[1] return //*[$x/following::* and $y/preceding::*] But it gives the error Error: Stopped at D:/Program Files/BaseX/data/test.xq, 1/74: [XPDY0002] root(): no context value...

Xquery add filename as an element

xquery,marklogic
1.xml <root> <name>aa</name> <phno>bb</phno> <email>cc</email> </root> 2.xml <root> <name>aa</name> <phno>dd</phno> <email>ee</email> </root> when I search for "aa", using search:search("aa"), gives me 1.xml and 2.xml in search results as uri attribute. Now, I need to convert these two documents into single JSON file with document uri in it. My approach is...

MarkLogic 8 and server-side JavaScript - XPath Queries on Sequences

javascript,xpath,xquery,marklogic
In XQuery, you can very efficiently execute an XPath query on an API function which returns a sequence: fn:collection("abstract")//author With server-side JavaScript, this doesn't seem to be possible. You can iterate the sequence in a loop, and execute an XPath query on the individual documents, but it can't be very...

Xquery Assertion for SoapUI multiple modes

xml,automation,xquery,soapui
I'm trying to create an assertion for a Response that needs to looks like this: <Names> <NameList PropertyName="Record"> <Names> <SimpleValue Value="Date :xx"/> <SimpleValue Value="Name :xx"/> </Names> </NameList> <NameList PropertyName="Record"> <Names> <SimpleValue Value="Date :xx"/> <SimpleValue Value="Name :xx"/> </Names> </NameList> </Names> The assertion should be an exact match. I have come up...

Find delta-difference between two xml File in marklogic

xml,xquery,marklogic
I have a requirement where i need to find difference between two XML file-Updated/Latest File(File1) and previous version(File2). The Updated XML file may have additional nodes or some nodes may be deleted. I have to compare this two XML and need to show differences. I am using deep-equal function two...

MarkLogic 8 - node.js API - Convert XML to JSON

node.js,xquery,marklogic
I am working learning the Javascript API for MarkLogic. I do a query: cts.search( cts.andQuery( [cts.wordQuery("abc"), cts.collectionQuery(["Strings"])] ) ); And get XML. I know how to convert this XML to JSON in XQuery, but how do I do it in Node? I can't seem to find it in the documentation....

XQuery: Select a node in the context of a varaible

xpath,xquery,basex
In order to learn XQuery I tried to run the following XQuery command in BaseX let $x := doc("test.xq")//h2/following-sibling return $x::h2 I supposed it should be equivalent to let $x := doc("test.xq")//h2/following-sibling::h2 return $x But it gives the following error and doesn't work while the second command works Error: Stopped...

XQuery “flattening” an element

xquery
I am extracting data from an XML file and I need to extract a delimited list of sub-elements. I have the following: for $record in //record let $person := $record/person/names return concat($record/@uid/string() ,",", $record/@category/string() ,",", $person/first_name ,",", $person/last_name ,",", $record/details/citizenships ,"&#10;") The element "citizenships" contains sub-elements called "citizenship" and as...

Return first value after if statement is true

xml,xquery
I have following xml: <test> <TestStruktur> <TestReference>ID_text_random_uuid</TestReference> <TestReference>ID_test_random_uuid</TestReference> <Name>Some name</Name> </TestStruktur> <TestStruktur> <TestReference>ID_test_random_uuid</TestReference> <TestReference>ID_text_random_uuid</TestReference> <Name>Some name</Name> </TestStruktur> </test> I need to search for TestReference elements and check if values contain...

XQuery with if condition in for loop

xquery,marklogic,exist-db
I have written xquery to return results in normal way. let $results := //data:data return <result> { for $i in $results return <documentInformation> <id>{data($i/DATA:ID)}</id> <status>{data($i/@status)}</status> <title>{data($i/data:title)}</title> <displayName>{data($i/DATA:DISPLAYNAME)}</displayName> </documentInformation> } </result> Now, I have to filter out the results in for loop with some condition like (pseudo logic) if id =...

Static content before loop

xquery,marklogic
Am new to XQuery. I have written below query which is working perfectly and producing results in csv format from an xml stored in Marklogic. xquery version "0.9-ml" let $data := someQuery return for $i in $data return fn:string-join(( $i/PATHTOFILED_1/text(), $i/PATHTOFILED_2/text(), . . . . $i/PATHTOFILED_N/text() ),"," ) Output: abc,def,adc,...

XQuery document node test with an element node test in BaseX 8.2 throws in the presence of comments before the root element. Why?

xml,xslt,xquery,saxon,basex
In BaseX 8.2, I'm trying to assign to an XQuery variable, a document node whose root element has a specific name. The source XML looks like this: <?xml version="1.0" encoding="utf-8"?> <!--A comment--> <myRootElement/> To get the document node, I type-check it using a DocumentTest: declare variable $docnode as document-node(element(myRootElement)) :=...

how to make xml values comma seperated using XPath, XQuery in Sql Server

sql-server,xml,xpath,xquery
I have an xml column with sample values as <error> <errorno>BL04002055</errorno> <description>Smart Rule PROJECT_COUNTRYCODE_VAL Violated</description> <description2>Country Code is required</description2> <correction /> </error> <error> <errorno>BL01001973</errorno> <description /> <description2>Error While Saving the Project info</description2> <correction /> </error> <error> <errorno>Unable to Create Custom...

How can I return JSONP in RestXQ (using eXist-db)?

jsonp,xquery,exist-db,restxq
I cannot figure out how to return JSONP in RestXQ. After adding let $x := util:declare-option("exist:serialize", fn:concat("method=json jsonp=",request:get-parameter("callback", "callback"))) to the function, I get the error message: err:XPTY0004:It is a type error if, during the static analysis phase, an expression is found to have a static type that is not...

Wilcards not working for XQuery assertions in SoapUI

xpath,groovy,xquery,soapui,assertions
This is the response for one of my test steps: <Names> <NameList PropertyName="Record"> <Names> <SimpleValue Value=" Date: MM/DD/Year "/> <SimpleValue Value="Name: John "/> <SimpleValue Value="Amount: 1234"/> <SimpleValue Value="Change: 2.0 "/> <SimpleValue Value="Total: 0.0 "/> </Names> </NameList> </Names> I'm expecting the exact match in my Xquery assertion except the value where...

fn:sum error “cannot cast to xs:double”

xpath,casting,sum,xquery
I'm trying to add up multiple nodes (names & amount of nodes uncertain). performing the query for $x in //onboard/* return $x returns this (and more) <total> <one/> </total> <total> <one>124</one> <two>1</two> <three>0</three> </total> <total> <one>46</one> </total> <total> <one>129</one> <two>1</two> <three>0</three> </total> <seafarers> <one>149</one> <two>3</two>...

Xquery transform error “Invalid coercion () as document-node()”

xml,xquery,marklogic
I'm trying to transform my search results into some-other format using XQuery. I'm using example XQuery transformation as in documentation like: xquery version "1.0-ml"; module namespace example = "http://marklogic.com/rest-api/transform/add-attr"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; declare function example:transform( $context as map:map, $params as map:map, $content as document-node() )...

XQuery XML insert

xml,xslt,xquery,transformation,osb
I have XML based target data: <myTargetData> <myMap> <pairs> <key>KEY_1</key> <value> <myMap> <pairs> <key>INNER_KEY_1</key> <value/> </pairs> <pairs> <key>INNER_KEY_2</key> <value/> </pairs> <pairs> <key>INNER_KEY_3</key> <value> <myMap> <pairs> <key>INNER_INNER_KEY_1</key> <value/> </pairs> <pairs> <key>INNER_INNER_KEY_2</key> <value/>...

Conditionally creating formatted string from elements and attributes in XQuery

xquery
I'm trying to convert an xml document into a specific tab separated flat file structure. Most of the elements can be mapped to single columns or concatenated simply using fn:string-join(), but I have some elements where the mapping is more complicated. An example element looks like this: <record> <details> <passports>...

XQuery - Doing math on elements within a sequence and aggregating results

function,operators,xquery,sequence,aggregation
I'm trying to execute a XQuery sum function in a multiplication of two XML elements, but it has been difficult to avoid the iteration in a sequence of elements. For example, consider this case: sample data: <Orders> <Order> <OrderKey>1</OrderKey> <LineItem> <LineNumber>1</LineNumber> <Quantity>41</Quantity> <ExtendedPrice>70848.0000</ExtendedPrice> <Discount>0.0913</Discount> <Tax>0.0663</Tax> <ReturnFlag>A</ReturnFlag>...

How can I replace text with angle bracket without parsing the replace value?

xslt,xquery
I have this: replace("Both cruciate ligaments are well visualized and are intact.", ".", ".&lt;br&gt;") But I do not want to output the escaped angle brackets but the actual brackets. when I run the code I get : Both cruciate ligaments are well visualized and are intact.&lt;br&gt; I want: Both cruciate...

XQuery: comparing datetimes with milliseconds

python,xpath,xquery,berkeley-db-xml
I have a validation module in Python that executes an XQuery on an XML document to check if any <Start> times come after <End> times, and return the count of them. The query is as follows: for $d at $count in ./ty:Detections/Detection where $d/Start > $d/End return $count Now this...

Using XMLTABLE and xquery to extract data from xml

oracle,plsql,xquery,xmltable
I have the following piece of XML: <per:Person xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.something.com/2014/11/bla/webservice.xsd" xmlns:per="http://www.something.com/2014/11/bla/person"> <per:Initials>E.C.</per:Initials> <per:FirstName>Erik</per:FirstName> <per:LastName>Flipsen</per:LastName> <per:BirthDate>1980-07-01</per:BirthDate> <per:Gender>Male</per:Gender> </per:Person> From this xml I want to...

Intersect search:search result set with cts:search result set that used cts:polygon geospatial search

full-text-search,xquery,intersection,marklogic,cts-search
I had to add geo-spatial search capability to an already existing app which uses search:search API and has full text search and faceted search. I've read about Extending the Search API, but I just don't have the time right now. So, I thought I will adapt my code in order...

Best UI interface/Language to query MarkLogic Data

xquery,marklogic
We will be moving from Oracle and use MarkLogic 8 as our datastore and will be using MarkLogic's Java api to talk with data. I am exploring for any UI tool (like SQL Developer is there for Oracle), which can be used for ML. I found that ML's Query Manager...

Is the order of two siblings implementation dependent?

xml,tree,documentation,xquery
If I have an XML document like this one: <people> <person> <name> Mario </name> <age> 25 </age> </person> <person> <name> Lucas </name> <age> 32 </age> </person> </people> Is always guaranteed that in the document order, Mario occurs before Lucas? so Lucas is always a following sibling of Mario, or it's...

Issues when adding a xml content with UTF-8 characters to an eXist-db collection using Perl

perl,utf-8,xquery,xml-rpc,exist-db
I am trying to add dynamically generated XML content to a eXist-db collection (see the code below addFile.pl) using Perl, the issue is that whenever the content contains UTF-8 characters I receive the error Failed to parse XML-RPC request: Byte "195" is not a member of the (7-bit) ASCII character...

XQuery substring for a sequence of items

substring,max,xquery
I want to extract all values of a column from a table, determine the maximum of those values, and return that value. This is what I tried: let $abc := doc("file:///some_local_file")//AOSCAT_MetricDetail//table[@class="pretty-table"]//tr/td[13] return <li>{ fn:max(fn:substring($abc,1,1)) }</li> But fn:substring can't handle a sequence of more than one item. So I tried this:...

For loop over every child elements

xquery
With my XML <products> <product id="12" type="modell"> <attribute type="image">nose.jpg</attribute> <product id="13" type="kid"> <attribute type="image">face.jpg</attribute> </product> </product> <product id="22" type="modell"> ... </product> </products> and xquery I except to get every attribute with type image under my product with id 12. What I tried so far: data(for $image in //product[@id = '12']/*/attribute[@type='IMAGE']...

How to escape Javascript in an XQuery function

javascript,xquery,marklogic
Is there a way to escape or render Javascript in a xquery function? Example: xquery version "1.0-ml"; module namespace tagmanager = "tagmanager"; declare function tagmanager() { < noscript > < iframe src = "//www.googletagmanager.com/ns.html?id=[value]" height = "0" width = "0" style = "display:none;visibility:hidden" > < /iframe></noscript > < script >...

How to use xpath or query to extract data from xml

c#,.net,xml,xpath,xquery
I have a xml file look like <info> <Data Name="ProcessName">-</Data> <Data Name="IpAddress">10.1.2.118</Data> <Data Name="IpPort">50118</Data> <Data Name="ProcessName">-</Data> <Data Name="IpAddress">10.1.2.119</Data> <Data Name="IpPort">50118</Data> <Data Name="ProcessName">-</Data> <Data Name="IpAddress">10.1.2.120</Data> <Data Name="IpPort">50118</Data> <Data Name="ProcessName">-</Data> <Data...

Regular Expressions in MarkLogic's xQuery

regex,xquery,marklogic
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 containing non-ISO-Latin characters :) let $regex := '[^\x00-\xFF]' let $results := fn:collection('mydocs')//myns:myelem[fn:matches(., $regex)]...

how to refer dynamically an xml file in Xquery in saxon

java,xml,xquery,saxon,xqj
I am using XQuery processor Saxon,Now we write our Xquery in a ".xqy" file where we refer the xml file on which we will perform Xquery.please see the example below- for $x in doc("books.xml")/books/book where $x/price>30 return $x/title Now I want to use dynamically generated xml not stored in some...

XQuery:How to count an element is empty or it does not exist?

count,xquery
I have a XML file containing elements with the following structure: <root> <listing> <seller_info name="1"/> <auction_info> <notes></notes> </auction_info> </listing> <listing> <seller_info name="2"/> <auction_info> <notes></notes> </auction_info> </listing> <listing> <seller_info name="3"/> <auction_info> </auction_info> </listing> <listing> <seller_info name="4"/> <auction_info>...

How do I get the contents of all of the nodes in a root node with SQL and XQuery?

tsql,sql-server-2012,xquery
I have the following table structure: CREATE TABLE SpecialTable ( Key UNIQUEIDENTIFIER, XMLField VARCHAR(MAX) ) In the first tuple: Key = "28384841-17283848-7836-18292939" XMLField = "<RootNode> <ForeignKey>92383829-27374848-1298-19283789</ForeignKey> <ForeignKey>47585853-27374848-4759-19283939</ForeignKey> <ForeignKey>37383829-27374848-3747-19283930</ForeignKey> </RootNode>" In another tuple, I see: Key = "89984841-17283848-7836-18292939" XMLField = "<RootNode>...

XPath test for node exists and contains a number

xml,xpath,xquery,domxpath,xquery-sql
I need a condition in XPath or XQuery to determine if a product has the node Id and if that node has a number. <ns34:Product> <ns34:Id>100</ns34:Id> </ns34:Product> <ns34:Product> <ns34:Id>104</ns34:Id> </ns34:Product> ...

capturing a sequence within a sequence

xquery
Say I have a sequence of items, <items> <item>B</item> <item>D</item> <item>A</item> <item>B</item> <item>C</item> </items> and I want to capture all sequences of A- and B-items <items> <item>B</item> <item>D</item> <hit> <item>A</item> <item>B</item> </hit> <item>C</item> </items> Can this be done with XQuery? When iterating, the context item is singular. I can get...

Generating XML output with XQuery / XPath expression matching nothing, why?

xquery
I am trying to generate the following xml output: <OrderDataUpdate xmlns=”http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25”> <TetheringType>IE Tethering</TetheringType> </OrderDataUpdate> But instead I get this(note the text content for TetheringType is not populated). <OrderDataUpdate xmlns="http://www.metasolv.com/OMS/OrderDataUpdate/2002/10/25"> <TetheringType/> </OrderDataUpdate> My input XML: <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"...

Escaping input for insertion into XQuery string

php,escaping,xquery,basex
Say I have the following code: let $search := "placeholder" ... ...functx:get-matches-and-non-matches($t,$search)... This code is stored like this in a file, gets loaded into a string (by PHP), placeholder gets replaced with user input, and then the code gets executed. Obviously, " needs to be escaped somehow. Is there any...

Outputing plain text with XQuery, Zorba & Eclipse

eclipse,code-generation,xquery,zorba
I am attempting to get my head around using XQuery on a project im working on. One thing that I will need to do is use XQuery to parse an XML model and output plain text (this plain text will actually be C++ code, as the project is to create...

Basic Xquery CRUD samples equivalent to SQL Select, Insert, Delete or Update [closed]

xquery,crud
I'm an engineer building products and applications traditionally on the RDBMS systems. I'd like to port the applications and products to MarkLogic, this is very convenient and efficient compared to RDBMS technology. However, there are no adequate CRUD examples for me to take off. Can anyone kindly lead me to...

TSQL Replace value in XML String

sql-server,tsql,sql-server-2012,xquery
I have a field within my table that contains optional fields of data contained as XML. One of those fields is editable in my UI and I am trying to update that node / value within the block of XML. Here is what I have: UPDATE dbo.TFS_Feedback_New SET Details.modify('replace value...

MS SQL XQuery xs:base64Binary returns NULL

sql-server,tsql,xquery
I (have to) use base64Binary to convert my base64 encoded string into bytes. In most cases it works good enough, but from time to time it returns NULL . For example this works like a charm: DECLARE @Base64String VARCHAR(MAX) SET @Base64String = 'qwerqwerqwerqwer' declare @Base64Binary VARBINARY(MAX) set @Base64Binary = cast(''...

Distinct attribute names

xquery
With XQuery I want to select a special value from every article within a product. What I currently have: Input XML (extract): <product type="product" id="2246091"> <product type="article"> <attribute identifier="EXAMPLE1" type="BOOLEAN">0</attribute> <attribute identifier="EXAMPLE2" type="BOOLEAN">1</attribute> </product> <product type="article"> <attribute identifier="EXAMPLE1" type="BOOLEAN">1</attribute> <attribute identifier="EXAMPLE2"...

SQL Server XML Update Serialized Array based on compound XQuery

sql-server,xml,xquery,xquery-sql,xquery-update
I have a db table with an XmlProperties column with data in the form of a Serialized .NET array. Here's an example: <ArrayOfKeyValueOfstringanyType xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/2003/10/Serialization/Arrays"> <KeyValueOfstringanyType> <Key>CompanyName</Key> <Value xmlns:d3p1="http://www.w3.org/2001/XMLSchema" i:type="d3p1:string">Company A</Value> </KeyValueOfstringanyType> <KeyValueOfstringanyType>...

SAXON - Calling external java functions in Xquery

java,xml,xquery,saxon
I have a requirement to invoke java function in Xquery using Saxon processor.I came to know that saxon has various editions like home, professional, enterprise editions. I am looking for a open source edition which can help me to invoke external java functions in xquery. Can somebody please help me...

How can I write code that works with the JSON API differences in MarkLogic 7 and 8?

json,xquery,marklogic
MarkLogic 8 improves JSON support in many ways, but some of the MarkLogic 7 JSON functions now have different signatures or do different things. How can I write XQuery code that works with both releases?

Marklogic index children

xml,indexing,xquery,marklogic
Is it possible to index on children elements? My data is setup like this <schedule id="ID_HERE" lang="LANGUAGE"> <scheduleItem id="CHILD_NODE_ID" lang="eng"> <dateTime> 2015-01-19T00:00:09-00:00 </dateTime> </scheduleItem> <scheduleItem id="CHILD_NODE_ID1" lang="eng"> <dateTime> 2015-01-19T00:00:09-00:00 </dateTime> </scheduleItem> <scheduleItem id="CHILD_NODE_ID2" lang="eng"> <dateTime> 2015-01-19T00:00:09-00:00 </dateTime> </scheduleItem>...

create a node with two attributes in Xquery

xml,xquery
I have XML as given below: <test> <a>Hello</a> </test> I need to add a new node with two attributes in XQuery and the expected output is: <test> <a>Hello</a> <b att1="1" att2="2">World</b> </test> Can you help me out with the XQquery for this?...

Saxon HE and XQuery: Unexpected token “

xquery,eof,saxon
I copy paste this example from http://www.w3schools.com/xquery/xquery_functions.asp (though I added the namespace declaration): declare namespace local="local"; declare function local:minPrice($p as xs:decimal?,$d as xs:decimal?) as xs:decimal? { let $disc := ($p * $d) div 100 return ($p - $disc) }; But when I try to run it, the SAXON output is:...

xQuery 1.0, element counting

count,xquery,sections
I have a problem with writting a XQuery. I have this XML file: <?xml version="1.0" encoding="UTF-8"?> <book> <title>Data</title> <author>Serge Abiteboul</author> <author>Peter Buneman</author> <author>Dan Suciu</author> <section id="intro" difficulty="easy" > <title>Chapter1</title> <p>Text ... </p> <section> <title>SubChapter1</title> <p>Text ... </p> </section> <section>...

How do I pass xquery through eXist-db's REST api?

rest,xpath,xquery,exist-db
I understand how to use Xpath http://localhost:8080/exist/rest/db/movies?_query=//movie[title=%22Spider-Man%22]/node() But how to pass an xquery query? I keep reading everywhere that the REST api is for both xpath and xquery but I can't get my query to work. Here is what I'm trying to pass as an example (I've tested this in...

Can I create a macro or shortuct for a step of XPath in XQuery?

xml,xpath,macros,xquery
Do we have Macros in XQuery? If yes, could you please give an example of their usage. I have the following code let $x := //price/ancestor::* Can I someway, using macros or other things write it as follows: let $x := //price/outward So, the outward should mean ancestor::*...

SQL Server 2008 R2: Only get NULL when using XQuery (.value) to query into XML

sql,sql-server,xml,sql-server-2008,xquery
My table is called Table_1 with 2 columns: id (int) and myxml (xml) I attached the xml snapshot I am working with below. (This xml corresponded to id = 1) The problem I have is that I only get NULL when using XQuery (.value) to query into this XML This...

XQuery / XPath: How to retrieve an attribute value from an ancestor node when using “|” operator?

xml,xpath,xquery
I'm applying an XQuery file to two XML files: -file1/snippet1- <entry xml:id="SCHOM-2"> <form type="hyperlemma" xml:lang="cu"> <orth>абиѥ</orth> </form> <form type="lemma" xml:lang="cu"> <orth>абиѥ</orth> <cit type="counterpart" xml:lang="grc"> <form type="hyperlemma" xml:lang="grc"> <orth>παραχρῆμα</orth> </form> <form type="lemma" xml:lang="grc"> <orth>παραχρῆμα</orth> </form> </cit>...

MarkLogic: Converting an XML document into an XML string using XQuery

xml,xquery,marklogic
I am using something like let $x := "<root> <parent1>value1</parent1> <parent2>value2</parent2> </root>" ... and converting the XML document to string. I wanted to pass an xml output from a function to another function as a string and not by hard coding it as I'm doing it right now. I tried...

XQuery: find max value and return relevant information

max,xquery
I have a XML file containing elements with the following structure: <listing> <auction_info> <num_bids>29</num_bids> </auction_info> <item_info> <result>item A</result> </item_info> </listing> <listing> <auction_info> <num_bids>12</num_bids> </auction_info> <item_info> <result>item B</result> </item_info> </listing> I need a query to calculate the max of num_bids and return the result.In my example,the num_bids 29 is the max...

Select XML elements into table rows in SQL Server

sql,xml,tsql,xpath,xquery
I have XML like the following in a single row within a table (there are many rows within the table): <?xml version="1.0" encoding="UTF-8"?> <AuditTrail> <Action /> <ActionDetail /> <ChangesXML> <Details> <Object ObjectType="Data.Review_Extension" AuditType="Modified" FriendlyName="Review"> <ObjectKeys> <ReviewExtID>21482283</ReviewExtID> </ObjectKeys> <Properties> <Property name="Document Type 01" FieldName="Document_Type_01" TemplateFieldID="644140"...

Xquery get second product sorted by name

xquery
From the following XML I want to get the nth product sorted by their @name: <products> <product name='200'>...</product> <product name='100'>...</product> <product name='111'>...</product> <product name='100'>...</product> <product name='110'>...</product> </products> I tried (to get the first, but must be also working to get the third and so on...): for $d in //products/product/[1] order...

Difference between [border @ country] and [border /@ country]

xml,xpath,xquery
I have a xml file and one line of the file is like this <mondial> <country> <encompassed continent="europe" percentage="100"/> </country> </mondial> let say I want to select the country that encompasses continent is europe so I wrote: <result> { doc("mondial.xml")//country[encompassed @continent="europe"]// city } </result> But the answer says <result> {...

Inconsistent Whitespace handling in XQuery?

xml,xquery
I'm confused about how to get XQuery to handle whitespace like I want it to. Say I have to following XML: <body> to<lb/> <choice norm="Miss">Mi<glyph ref="#sm-long-s>s</glyph>s</choice> <name type="person"><forename>Margaret</forename> <surname>Hamilton</surname></name><lb /> <name type="place">S<hi rend="superscript">t</hi> James's</name> </body> If I use this code for $body in /body return replace(string-join( for $t in $body//node()...

how do I xPath to a value in a select statement in SQL Server?

sql,sql-server,xpath,xquery
XML is in a column in a table. I want to select this specific value: <CreditDebitAdjustments xmlns="http://...."> <CreditDebitAdjustment> <Header> <CreditDebitAdjustmentHeader> <Amount>-111.58</Amount> Here's what I tried to do: SELECT *, XMLPayload.query('/CreditDebitAdjustments/CreditDebitAdjustment/Header/CreditDebitAdjustmentHeader/Amount') AS Amount FROM Table WHERE CustomerID = 8 How do I go about extracting the value -111.58?...

Select comment()'s before root node

xml,xpath,xquery,exist-db
This is a distraction turned obsession. I was messing around in eXist and decided to get the comment() from the document. Only problem is most of our comments come before the root node. Let's take an example XML <?xml version="1.0" encoding="UTF-8"?> <!-- DOCUMENT REVIEWED --> <doc id="test"> <figure> <figcaption>caption</figcaption> </figure>...

Can't iterate over the elements on and xml file with xquery

xml,xquery,exist-db
I 've got a xml file with this structure: <profiles> <profile profile="SuperAdministrator" name="admin"/> <profile project="TesteHandSpy" profile="Researcher" name="john"/> <profile project="DunnProject,DAAR1_op,Sara" profile="Researcher" name="juliete"/> </profiles> And I want to select the project value of profile elements with a certain value for attribute name. I started trying to just list all profile elements and...

Fetching data from xml Using Xquery with starts with function

java,xml,xquery
I want to fetch a data from xml Using Xquery with starts with function. data.xml <data><employee id=\"1\"><name value=\"vA-12\">A</name> <title id=\"2\">Manager</title></employee> <employee id=\"2\"><name value=\"vC-12\">C</name><title id=\"2\">Manager</title></employee> <employee id=\"2\"><name value=\"vB-12\">B</name><title id=\"2\">Manager</title></employee> </data> Now I want to fetch that name which has...