Hi,
This should work indeed, as a descent recursive copy. Given there
is no attribute at all in the element to return. A couple of comments
though:
- there is no document node involved in this example, but if you match
the case in the function, the most sensible thing to do is to create a
document node in the copy as well
- in XDM, a document node can have several children, elements and
other nodes as well, here you selecting only the first element
- matching explicitly the cases for PIs and comment nodes does not
make more sense, especially when not handling text nodes explicitly
So I guess this one version would be more reusable:
declare function local:copy-tree($node as node()) as node()
{
typeswitch($node)
(: create a document node and recurse :)
case document-node() return
document {
$node/node() ! local:copy-tree(.)
}
(: create an element node, copy attributes, and recurse :)
case element() return
element { fn:node-name($node) } {
$node/@*,
$node/node() ! local:copy-tree(.)
}
(: return $node as is, will be copied when added to another parent :)
default return
$node
};
PS: Not tested.
Regards,
--
Florent Georges
http://fgeorges.org/
http://h2oconsulting.be/
On 22 July 2015 at 15:16, Indrajeet Verma wrote:
> Hi Raghu,
>
> Can you try this and see if works for you?
>
> declare namespace ns="http://somewhere.something.com";
> xdmp:document-insert
> (
> "/text.xml",
> <ns:root>
> <child xmlns="http://anywhere.anything.com"></child>
> </ns:root>
> );
> declare function local:reparse-doc($node)
> {
> typeswitch($node)
> case document-node() return
> local:reparse-doc($node/*[1])
> case element() return
> element { fn:node-name($node) } {
> $node/node() ! local:reparse-doc(.)
> }
> case processing-instruction() return $node
> case comment() return $node
> default return $node
> };
> let $doc := doc("/text.xml")//*:child
> return local:reparse-doc($doc)
>
> Regards,
> Indy
>
> On Wed, Jul 22, 2015 at 6:28 PM, Raghu <[email protected]>
> wrote:
>>
>> Thanks Florent Georges!
>>
>> On Wed, Jul 22, 2015 at 7:42 AM, Florent Georges <[email protected]>
>> wrote:
>>>
>>> Hi,
>>>
>>> Just to make it clear, there is nothing wrong with using several
>>> namespaces in the same document. Namespaces have been invented to
>>> differentiate names (by creating uniquely identified "spaces" for
>>> them). So their unit of application is element and attribute names,
>>> rather than documents.
>>>
>>> Think for instance about embedding SVG and MathML elements in a
>>> XHTML or XSL-FO document. The namespaces will ensure that elements
>>> with the (local) name "title" can be differentiated, by looking at
>>> within what namespace they have been defined.
>>>
>>> Regards,
>>>
>>> --
>>> Florent Georges
>>> http://fgeorges.org/
>>> http://h2oconsulting.be/
>>>
>>>
>>> On 21 July 2015 at 19:30, Asit Nautiyal wrote:
>>> >
>>> > Hi Raghu,
>>> >
>>> > Here you want to keep the text.xml as part of
>>> > "http://somewhere.something.com" namespace and want to make its child
>>> > element (child) part to other namespace ""http://anywhere.anything.com"
>>> > ,
>>> > correct me, if I am wrong!
>>> >
>>> > If this is the case then, you are making this xml file as ambiguous. In
>>> > xml
>>> > file , all child elements should belongs to same namespace as its root
>>> > element, that's why we have concept of namespace.
>>> >
>>> > Regards,
>>> > Asit Nautiyal
>>> > ________________________________
>>> > Date: Tue, 21 Jul 2015 11:07:53 -0400
>>> > From: [email protected]
>>> > To: [email protected]
>>> > CC: [email protected]
>>> > Subject: [MarkLogic Dev General] Need to remove unused xml namespace
>>> > prefix
>>> >
>>> >
>>> > HI All,
>>> >
>>> > The following snippet gives me the unused namespace prefix (in this
>>> > case
>>> > ns), I need to ignore such unused namespace prefixes in the output
>>> >
>>> > Query
>>> >
>>> > declare namespace ns="http://somewhere.something.com";
>>> > xdmp:document-insert
>>> > (
>>> > "/text.xml",
>>> > <ns:root>
>>> > <child xmlns="http://anywhere.anything.com"></child>
>>> > </ns:root>
>>> > );
>>> > doc("/text.xml")//*:child
>>> >
>>> > Result
>>> >
>>> > <child xmlns:ns="http://somewhere.something.com"
>>> > xmlns="http://anywhere.anything.com"/>
>>> >
>>> > Thanks in advance!
>>> > Raghu
>>> >
>>> > _______________________________________________ General mailing list
>>> > [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
>>> >
>>> _______________________________________________
>>> General mailing list
>>> [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
>>
>
>
> _______________________________________________
> General mailing list
> [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