You could always remove the namespaces before you perform the quote.    This is 
a simple version for this example and you could write a recursive function if 
you have children nodes.

let $nodes-without-namespaces :=
     for $node in $nodes
     return
          element {fn:local-name($node)} {
             $node/@*,
             $node/text()
          }

let $quote :=xdmp:quote($nodes-without-namespaces)
let $string := for $i in $nodes-without-namespaces
                return fn:string($i)
let $length:= for $i in $nodes-without-namespaces
                return fn:string-length(fn:string($i))
…


Brad Rix | Technical Lead
O: +1 303 542 2172 | M: +1 303 915 2771
Skype: Brad.Rix | Google Talk: [email protected]

From: [email protected] 
[mailto:[email protected]] On Behalf Of Jonna Marry
Sent: Wednesday, May 06, 2015 8:49 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Calculating Node size

Hi Mary,
We tried using fn:string. it will extract only the text node of each element. 
we need to include the number of character in element name. ie need to count 
<info:name lang="en" >Logging Ltd2.</info:name> ignoring only namespace.
Query executed:
declare namespace info = "http://www.aaa-aaa.com/info";;
let $nodes := (<info:name lang="en"  >Logging Ltd.1</info:name> ,
<info:name lang="en" >Logging Ltd2.</info:name>,
<info:name lang="en"  >Logging Ltd.3</info:name>,
<info:name lang="en"  >Logging Ltd4.</info:name>
)
let $quote :=xdmp:quote($nodes)
let $string := for $i in $nodes
                return fn:string($i)
let $length:= for $i in $nodes
                return fn:string-length(fn:string($i))

return
<results>
<xdmpQuote>{$quote}</xdmpQuote>
<xdmpQuoteLength>{fn:string-length($quote)}</xdmpQuoteLength>
<fnString>{$string}</fnString>
<fnStringLength>{fn:sum($length)}</fnStringLength>
</results>

Output:

<results><xdmpQuote><info:name lang="en" 
xmlns:info="http://www.aaa-aaa.com/info";>Logging Ltd.1</info:name>
<info:name lang="en" xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd2.</info:name>
<info:name lang="en" xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd.3</info:name>
<info:name lang="en" xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd4.</info:name></xdmpQuote><xdmpQuoteLength>351</xdmpQuoteLength>
<fnString>Logging Ltd.1 Logging Ltd2. Logging Ltd.3 Logging Ltd4.</fnString>
<fnStringLength>52</fnStringLength></results>

Regards,
Jonna

On Wed, May 6, 2015 at 8:52 AM, Mary Holstege 
<[email protected]<mailto:[email protected]>> wrote:

Use fn:string instead of xdmp:quote
On May 6, 2015 5:32 AM, Jonna Marry 
<[email protected]<mailto:[email protected]>> wrote:
Hi,
We need to calculate the character length of a Node. By applying xpath we are 
getting the sequence of nodes. We need to calculate the length of each node 
along with nodename and text values. Since we have same name space in all the 
element we want to ignore the namespace char length.
Is there any way to ignore namespaces only for size calculation.

For example:
let $nodes := (<info:name lang="en"  
xmlns:info="http://www.aaa-aaa.com/info";>Logging Ltd.1</info:name> ,
<info:name lang="en"  xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd2.</info:name>,
<info:name lang="en"  xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd.3</info:name>,
<info:name lang="en"  xmlns:info="http://www.aaa-aaa.com/info";>Logging 
Ltd4.</info:name>
)
For single node
Without namespace  size= 48
With namespace  size= 88
currently we are using fn:string-length( xdmp:quote($nodes[1])).
Regards,
Jonna

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to