XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
neo kSubject: Issue with data($element)
Author: neo k
Date: 21 Aug 2008 12:34 PM
Hi All,
In the below example,

<books>
<book >
<information>
<name> HF </name>
<pages>45</pages>
</information>
</book>
<book>
<information>
<name>Core</name>
<pages>67</pages>
</information>
</book>
</books>

When i try,
data(doc("book.xml")/books/book/information))

the output in StylusStudio is
HF 45 Core 67868

which is something i expected. But when i try the same in Marklogic database I get it in

HF45Core67868

how can i modify my query to get the output like

HF 45 Core 67868

Thanks
Neo.

Postnext
Minollo I.Subject: Issue with data($element)
Author: Minollo I.
Date: 21 Aug 2008 12:48 PM
Isn't this a question for MarkLogic support?

Postnext
neo kSubject: Issue with data($element)
Author: neo k
Date: 21 Aug 2008 01:14 PM
Minollo,
Thanks any way.

--
Neo

Posttop
Hans-Juergen RennauSubject: Issue with data($element)
Author: Hans-Juergen Rennau
Date: 05 Sep 2008 06:20 PM
The “data” function atomizes its operand, that is, turns it into a sequence of atomic values. For each node in the input sequence, “data” returns the data value, which is, in the absence of schema validation, the concatenation of all text node descendants, without any seperators strewn in. So the data value of the first <information> element is “ HF 45” (note the blanks in the input!), and “Core67” for the second element.

If you let your path expression produce final result, you rely on how this *sequence* of values is serialized – and the differences you observed are simply differences of serialization, I presume. (In fact, blanks SHOULD be inserted.) The alternative is to control the output yourself by building the desired string representation in your query. You can do so using the “string-join” function.

a) If you are content with the representations of the <information> as is and only want to separate them by blank, use this expression:

string-join(data($books/book/information), " ")
Result for your example: “ HF 45 Core67”

b) If you want to separate also the child items of <information> themselves by a blank, do this:

string-join($books/book/information/*, " ")
Result: “ HF 45 Core 67“

c) To get rid of the spurious blanks occurring within those elements (like “ HF “), use this:

string-join($books/book/information/*/normalize-space(), " ")
Result: HF 45 Core 67

d) To set different seperators between and within the <information> representations, try this:

string-join($books/book/information/string-join(*/normalize-space()," "),", ")
Result: HF 45, Core 67


Hope this helps!

With kind regards –
Hans-Juergen Rennau

 
Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.