Hi kelly,

        Thanks for your reply.,  It worked well.,

Santhosh Rajasekaran
Tata Consultancy Services
Mailto: [email protected]
Website: http://www.tcs.com
____________________________________________
Experience certainty.   IT Services
                        Business Solutions
                        Outsourcing
____________________________________________



Kelly Stirman <[email protected]> 
Sent by: [email protected]
05/16/2009 03:42 AM
Please respond to
General Mark Logic Developer Discussion <[email protected]>


To
"'[email protected]'" <[email protected]>
cc

Subject
Subject: Re: [MarkLogic Dev General] How to add attributes to 
existingnodesor  replace only the attribute of an element - reg.,






Wyatt is right - attributes are nodes too. :-)

So, his second example can be simplified to use xdmp:node-insert-child 
instead of xdmp:node-replace():

let $book := doc("book.xml")/bib/book[1]
return
    xdmp:node-insert-child($book,
        attribute year {2009}
    )

I would combine both operations in an if/then statement:

let $t := doc("book.xml")/bib/book
return 
if($t/@year)
then xdmp:node-replace($t/@year, attribute year {"1999"})
else xdmp:node-insert-child($t, attribute year {"1999"})
 
Wyatt managed to mention all the other node update built ins, so I'm not 
sure how he overlooked this one. :-) 

Perhaps it is because it isn't obvious that attributes are children of 
elements, at least not to me. 

(Forgive typos - currently away from my computer)

Kelly

Message: 2
Date: Fri, 15 May 2009 08:52:47 -0400
From: Wyatt VanderStucken <[email protected]>
Subject: Re: [MarkLogic Dev General] How to add attributes to existing
nodesor  replace only the attribute of an element - reg.,
To: General Mark Logic Developer Discussion
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"

An attribute() is also a node(), so xdmp:node-replace() is the right 
function...

Update is really easy...
let $oldYear as attribute() := doc("book.xml")/bib/book[1]/@year,
    $newYear as attribute() := attribute year {2005}
return xdmp:node-replace($oldYear, $newYear)

Adding it initially (since the book element has no other attributes) is 
slightly less straight forward...
let $book := doc("book.xml")/bib/book[1]
return
    xdmp:node-replace($book,
        element book {
            attribute year {2009},
            $book/*
        }
    )

If the book element had other attributes you could use 
xdmp:node-insert-after() or xdmp:node-insert-before().

Regards,
Wyatt
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

ForwardSourceID:NT0000BA22 
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain 
confidential or privileged information. If you are 
not the intended recipient, any dissemination, use, 
review, distribution, printing or copying of the 
information contained in this e-mail message 
and/or attachments to it are strictly prohibited. If 
you have received this communication in error, 
please notify us by reply e-mail or telephone and 
immediately and permanently delete the message 
and any attachments. Thank you


_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to