1
votes

I have wrote a xquery program to make a translation from one xml file to another. Everything goes right. But if I insert a namespace (directly as an attribute in the root element or with declare default element namespace "";) in xquery for the result my FLWOR-statment isn't considered. Then I receive an empty result set. Where is the problem? What should I do to become the result? Thanks for an answer.


Thanks a lot for the answers. But this solves not really my problem. I try to formulate the problem clearer. The xquery program should convert gpx-files to kml-files. So I am concerned with two default namespaces. The default namespace xmlns="http://www.topografix.com/GPX/1/1" that is normally in the source document and the default namespace xmlns="http://www.opengis.net/kml/2.2" that should be in the result kml document. Has anybody an idea how to formulated this in xquery? Without the default namespace in the gpx and kml documents the program works fine, but all my gpx-files has the default namespace set and I also would like to have the respective default namespace in the kml files. How must I proceed? Thanks a lot.

3

3 Answers

2
votes

You can ignore the default namespace in the input document, by using namespace agnostic *: element tests like:

/*:gpx/*:trk

Also the namespace prefix (or absence of it) does not matter in namespace comparisons, only the url. So you can match ` with

declare namespace tempfoobar = "http://www.topografix.com/GPX/1/1";
/tempfoobar:gpx

You can also redefine the default namespace for your output. Like

declare default element namespace "http://www.topografix.com/GPX/1/1";
let $a := /gpx 
return
  <kml xmlns="http://www.opengis.net/kml/2.2">{$a}</kml>
0
votes

Check if the element you are returning has the same namespace as you are setting in the root element.

0
votes

I don't think you should be inserting the namespace as an attribute. I don't think xmlns is really an attribute and shouldn't be treated as such. Try pulling in whatever values you want to translate and create a new element within your new namespace.

declare namespace ns1 = "ns1"; declare namespace ns2 = "ns2";

let $source_node := $doc/ns1:whatever/ns1:node/ns1:your/ns1:translating

let $new_doc := <ns2:SOME_ELEMENT>{$source_node/text()}</ns2:SOME_ELEMENT>

then child insert it or whatever you want to do with it. Or you could use XSLT...