I suggest a simpler approach is to simply predecease all namespaces on your root node. The serializer then will (should) omit redundant namespace declarations on child nodes.
---------------------------------------- David A. Lee [email protected] http://www.xmlsh.org -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of Robby Pelssers Sent: Thursday, August 23, 2012 7:44 AM To: [email protected] Subject: [xquery-talk] how to copy namespaces to root tag (to avoid repetition) Hi all, I've setup a small test case and was trying to see the effect of the copy-namespaces instruction. What I am trying to achieve is to have the root tag (in this case rdf:RDF) declare all used namespaces so that the result of the XQuery becomes much smaller for big result sets. Any pointers on how to achieve this? Thx in advance, Robby ******************************************************************* declare namespace convert2rdf = "http://www.nxp.com/convert2rdf"; declare copy-namespaces preserve, inherit; declare namespace rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; declare namespace skos="http://www.w3.org/2004/02/skos/core#"; declare namespace foaf="http://xmlns.com/foaf/0.1/"; declare namespace nxp="http://purl.org/nxp/schema/v1/"; declare function convert2rdf:basicType($product as element(product)) { <rdf:RDF>{convert2rdf:basicTypeRaw($product)}</rdf:RDF> }; declare function convert2rdf:basicTypeRaw($product as element(product)) { let $btn := data($product/name) return <rdf:Description rdf:about="http://data.nxp.com/basicTypes/{$btn}"> <rdf:type rdf:resource="http://purl.org/nxp/schema/v1/BasicType"/> <skos:prefLabel xml:lang="en-us">{data($product/description)}</skos:prefLabel> <foaf:homepage rdf:resource="http://www.nxp.com/pip/{$btn}"/> <nxp:typeNumber>{$btn}</nxp:typeNumber> </rdf:Description> }; let $product := <product> <name>PH3330L</name> <description>N-channel TrenchMOS logic level FET</description> </product> (: return convert2rdf:basicType($product) :) (: return convert2rdf:basicTypeRaw($product) :) ********************** output from convert2rdf:basicType($product) ************************* <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="http://data.nxp.com/basicTypes/PH3330L"> <rdf:type rdf:resource="http://purl.org/nxp/schema/v1/BasicType"/> <skos:prefLabel xmlns:skos="http://www.w3.org/2004/02/skos/core#" xml:lang="en-us">N-channel TrenchMOS logic level FET</skos:prefLabel> <foaf:homepage xmlns:foaf="http://xmlns.com/foaf/0.1/" rdf:resource="http://www.nxp.com/pip/PH3330L"/> <nxp:typeNumber xmlns:nxp="http://purl.org/nxp/schema/v1/">PH3330L</nxp:typeNumber> </rdf:Description> </rdf:RDF> ********************** output from convert2rdf:basicTypeRaw($product) ************************* <rdf:Description xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" rdf:about="http://data.nxp.com/basicTypes/PH3330L"> <rdf:type rdf:resource="http://purl.org/nxp/schema/v1/BasicType"/> <skos:prefLabel xmlns:skos="http://www.w3.org/2004/02/skos/core#" xml:lang="en-us">N-channel TrenchMOS logic level FET</skos:prefLabel> <foaf:homepage xmlns:foaf="http://xmlns.com/foaf/0.1/" rdf:resource="http://www.nxp.com/pip/PH3330L"/> <nxp:typeNumber xmlns:nxp="http://purl.org/nxp/schema/v1/">PH3330L</nxp:typeNumber> </rdf:Description> _______________________________________________ [email protected] http://x-query.com/mailman/listinfo/talk _______________________________________________ [email protected] http://x-query.com/mailman/listinfo/talk
