From: Dan M. <dan...@gm...> - 2010-09-05 13:58:53
|
Paolo, You are right that it has something to do with how we are creating nodes in our copy function and your work using in-scope-prefixes and QName functions seems to be going in exactly the right direction. I have modified a test case here: xquery version "1.0"; (: here are the two global options dealing with namespaces declare copy-namespaces preserve, no-inherit; declare copy-namespaces no-preserve, inherit; See chapter 10 in the XQuery book http://www.datypic.com/books/xquery/chapter10.html http://www.xqueryfunctions.com/xq/fn_qname.html http://www.xqueryfunctions.com/xq/fn_resolve-qname.html http://www.xqueryfunctions.com/xq/fn_local-name-from-qname.html :) declare function local:copy ($in as node()*) as item()* { typeswitch ($in) case element(none) return ( ) case text() return $in default let $name := name($in) let $ns-prefix := return (: we need to figure out how to create elements with the correct prefix and namespaces declarations :) element {local-name($in)} { (: for debugging get all the namespaces in context but remove the default XML namespace and display as attribute for testing... :) for $nsp in remove(in-scope-prefixes($in), 1) return attribute {concat('xmlns-', $nsp)} {namespace-uri-for-prefix($nsp, $in)}, $in/@*, for $e in $in/(* | text()) return local:copy($e) } }; let $in := <r xmlns:g="global"> <!-- declare a namespace but don't use it --> <a xmlns:a="a">A</a> <!-- declare a namespace but don't use it --> <a xmlns:a="namespace-a"> <a:a>A</a:a> </a> <b xmlns:b="nsb">B</b> <a xmlns:a="nsa"> <b xmlns:b="nsb">B </b> </a> <c xmlns:c="nsc">C</c> <c></c> </r> return local:copy($in) Which returns the following: <?xml version="1.0" encoding="UTF-8"?> <r xmlns-g="global"> <a xmlns-a="a" xmlns-g="global">A</a> <a xmlns-a="namespace-a" xmlns-g="global"> <a xmlns-a="namespace-a" xmlns-g="global">A</a> </a> <b xmlns-b="nsb" xmlns-g="global">B</b> <a xmlns-a="nsa" xmlns-g="global"> <b xmlns-b="nsb" xmlns-a="nsa" xmlns-g="global">B </b> </a> <c xmlns-c="nsc" xmlns-g="global">C</c> <c xmlns-g="global"/> </r> What I can not figure out is how to force the element constructor to copy the namespace declarations exactly as they are in the source. This runs the same in eXist and saxon. - Dan On Sun, Sep 5, 2010 at 8:29 AM, Paolo Di Pietro <pdi...@di...>wrote: > Dan, > > > > I’m using the following function to manage namespaces in attribute content: > > > > let $pins := > > for $n in in-scope-prefixes($workflow > //definitionContext) > > return <namespace prefix="{$n}" uri="{ > namespace-uri-for-prefix($n,$workflow//definitionContext)}"/> > > > > let $prefix := substring-before($instanceName, ":") > > let $postfix := substring-after($instanceName,":") > > let $name := > > if (empty($prefix) or empty($pins)) then > > $instanceName > > else > > let $pin := $pins[@prefix eq $prefix] > > return > > if empty($pin) then > > $instanceName > > else > > QName($pin > /@uri,concat($pin/@prefix,":",$postfix)) > > > > This solve my problem but I think that there should be a problem with the > parser (saxon?): if and how it recognize attribute data of type xs:QName. I > say this, because if I have an attribute or an element, the parser copy the > namespace, whilst if I have a content, it doesn’t. > > > > Of course, locally I can access the xsd which contains the definition. If > you need it I’ll publish it but it’s easy to reproduce creating an attribute > with xs:QName content > > > > > > Regards > > > > Paolo > > > > > > > > > > *Da:* Dan McCreary [mailto:dan...@gm...] > *Inviato:* domenica 5 settembre 2010 14:36 > > *A:* Paolo Di Pietro > *Cc:* exi...@li... > *Oggetto:* Re: [Exist-open] copying namespaces for QName > > > > Hello Paolo, > > I am sorry I did not respond to this in order. This question is more > complex and I am still trying to understand how to get it to work the way > you want it. You are working with a complex set of somewhat nonstandard > systems... but still valid systems. And I still do not understand why you > need namespaces at lower levels in the if you are not changing the namespace > but I will still try to find a solution. Usually all namespaces are > declared in the root element. > > I took the attached query and ran it in eXist and also under saxon and got > the exact same results. So I think that eXist is running OK. > > I also see that the namespace definitions are being dropped since the copy > function is not adding them as you indicated. So it is not a problem with > your local system. I believe our problem is in the copy function. But I > think you also see this also so I am really just verifying that this is the > source of our challenge. > > What I do not know is how to find all the namespace definitions in a node > and add them to the output. This will need some research. > > - Dan > > On Fri, Sep 3, 2010 at 7:59 AM, Paolo Di Pietro <pdi...@di...> > wrote: > > Thank you for your attention, > > > > of course NO! > > > > But the xquery must be unaware of the content it’s copying, so I cannot > know in advance of the namespaces that will be used in a document. > > > > The real question is that I need to copy a document, changing some node. So > I’m using a typeswitch where the default case looks as follow: > > > > default return > > element {name($n)} { > > $n/@* > > ,someOtherStuffsHere() > > } > > > > > > But the result is that the namespace definition on the nodes are not copied > (because they are not attribute) > > For the node <processContext xmlns:Azienda=" > http://arianna.diviana.net/workflow/infrastructure/agency" xmlns:utente=" > http://arianna.diviana.net/workflow/actor/user"> > > The result is <processControl> > > > > The namespace:: axis has been deprecated …. > > > > So here I am > > > > Paolo > > > > > > *Da:* Dan McCreary [mailto:dan...@gm...] > > *Inviato:* venerdì 3 settembre 2010 15:08 > > *A:* Paolo Di Pietro > *Cc:* exi...@li... > > *Oggetto:* Re: [Exist-open] copying namespaces for QName > > > > Have you correctly defined your namespace in XQuery? > > See: > > http://en.wikibooks.org/wiki/XQuery/eXist_Crib_sheet#declare_a_namespace > > for example do you have the following at the top of your XQuery? > > *declare namespace Azienda="**http://arianna.diviana.net/workflow/infrastructure/agency";* > > > > > > On Fri, Sep 3, 2010 at 7:36 AM, Paolo Di Pietro <pdi...@di...> > wrote: > > Hi all, > > > > I’ve still problems managing namespace in XQuery. > > > > I’ve the following fragment: > > > > <workflow xsi:noNamespaceSchemaLocation=" > http://vm-w:8080/exist/rest/db/arianna/naus/default/xsd/workflow.xsd"xmlns:xsi > ="http://www.w3.org/2001/XMLSchema-instance" xmlns:fn=" > http://www.w3.org/2005/xpath-functions"> > > <process area="naus:infrastructure" name="SceltaServizio"xmlns:naus > ="http://arianna.diviana.net/workflow/infrastructure/naus" debug="true"> > > <processContext xmlns:Azienda=" > http://arianna.diviana.net/workflow/infrastructure/agency" xmlns:utente=" > http://arianna.diviana.net/workflow/actor/user"> > > <role name="utente:utente"> > > <activity xsi:type=" > operatingActivity" name="SelezionaAzienda"> > > <description/> > > <preCondition> > > < > instance name="Azienda:Azienda"/> > > > …………………………. > > > > Both name attributes are of type xs:QName, and the file correctly validate. > > > > The following instruction give me the ‘XPST0081: No namespace defined for > prefix Azienda’ while it is currently defined in the processContext node > > > > declare copy-namespaces preserve, inherit; > > return element x { > > $workflow/process/processContext > > ,element Azienda:Azienda {<something />} > > } > > > > > Anyone has a suggestion? > > > > Thanks to everybody. > > > > Paolo > > > > ------------------------------------------------------------------------------ > This SF.net Dev2Dev email is sponsored by: > > Show off your parallel programming skills. > Enter the Intel(R) Threading Challenge 2010. > http://p.sf.net/sfu/intel-thread-sfd > _______________________________________________ > Exist-open mailing list > Exi...@li... > https://lists.sourceforge.net/lists/listinfo/exist-open > > > > > -- > Dan McCreary > Semantic Solutions Architect > office: (952) 931-9198 > cell: (612) 986-1552 > > > > > -- > Dan McCreary > Semantic Solutions Architect > office: (952) 931-9198 > cell: (612) 986-1552 > -- Dan McCreary Semantic Solutions Architect office: (952) 931-9198 cell: (612) 986-1552 |