[xquery-talk] xpath default namespace

Graydon Saunders graydonish at gmail.com
Sun Jun 5 14:20:13 PDT 2016


And just possibly some way to flush the haze of unwanted namespaces
clinging to the query result, too.

-- Graydon

On Sun, Jun 5, 2016, 17:17 Leo Studer <leo.studer at varioweb.ch> wrote:

> Thank you Mike And Ghislain
>
> may be  xPath/xQuery 3.2 will have the possibility of different default
> namespaces for input and output elements ;-)
> and also the possibility to bind a prefix to the null namespace (“”) ...
>
> Always
> Leo
>
>
>
> On 01 Jun 2016, at 13:15, Michael Kay <mike at saxonica.com> wrote:
>
> If the input and output are both in a namespace, and you want the output
> to be in a namespace but with no namespace prefix, then I think your
> options are:
>
> (a) Use *:name in path expressions (which may over-select)
>
> (b) Bind a prefix p to the input namespace and use p:name in path
> expressions (which is tedious)
>
> (c) Use Q{}name in path expressions (which is 3.0 only, and tedious)
>
> (d) Use computed element constructors, and binding the default namespace
> to the input namespace
>
> (e) Use XSLT 2.0 with the default-xpath-namespace attribute.
>
> Sadly, I remember trying to persuade the XQuery WG to allow different
> default namespaces for input and output element names, and the general
> reaction was "Mike, why do you keep trying to make namespaces even more
> complicated than they are already?". So XQuery repeated the mistake of XSLT
> 1.0, only in a slightly different form.
>
> Handling input documents with a default namespace remains by a good
> measure the #1 xpath usability problem, a new StackOverflow user falls into
> the trap nearly every day.
>
> Michael Kay
> Saxonica
>
>
>
>
> On 1 Jun 2016, at 10:44, Ghislain Fourny <g at 28.io> wrote:
>
> Hi Leo,
>
> I'm glad!
>
> Should this happen, I guess you could add a filter using an XPath function
> to test for the namespace of the name of the selected element.
>
>
> https://www.w3.org/XML/Group/qtspecs/specifications/xpath-functions-30/html/Overview.html#func-node-name
> and
>
> https://www.w3.org/XML/Group/qtspecs/specifications/xpath-functions-30/html/Overview.html#func-namespace-uri-from-QName
>
> You can test for the absence of namespace easily.
>
> There may be even shorter tricks, I wouldn't be surprised if Mike got
> something out of his magic hat :-)
>
> Kind regards,
> Ghislain
>
>
> On Wed, Jun 1, 2016 at 11:38 AM, Leo Studer <leo.studer at varioweb.ch>
> wrote:
>
>> Hi Ghislain
>>
>> thank you for your input, which solves my problem.
>>
>> However, if I have the same element name in two different namespaces,
>> then the use of a wildcard namespace makes problems ;-).
>>
>> Always
>> Leo
>>
>> On 01 Jun 2016, at 11:06, Ghislain Fourny <g at 28.io> wrote:
>>
>> Hi Leo,
>>
>> If the input has no namespace, then I think you can declare the default
>> namespace according to your output (if it is important to you that your
>> output uses it as a default namespace).
>>
>> Then there is a workaround to navigate the input with /*:foo/*:bar
>> expressions, where the joker prefix should catch the absence of namespace.
>>
>> I hope it helps?
>>
>> Kind regards,
>> Ghislain
>>
>>
>> On Wed, Jun 1, 2016 at 10:20 AM, Leo Studer <leo.studer at varioweb.ch>
>> wrote:
>>
>>> Hi Michael
>>>
>>> >
>>> >
>>> > The main difference from the XSLT xpath-default-namespace is that this
>>> default applies both to names in path expressions and to names in element
>>> constructors, which is inconvenient when the input and output documents are
>>> in different namespaces.
>>> >
>>> > Michael Kay
>>> > Saxonica
>>>
>>> this is exactly my problem. The XML file has no namespace and the output
>>> has a namespace.
>>>
>>> Fist I tried
>>>
>>>         declare namespace null=“”;
>>>
>>> and in the query I wrote something like
>>>
>>>         null:elementName
>>>
>>> Then I get the error that namespace null is not declared….
>>>
>>> The only solution I found is to put a namespace in the XML file (which
>>> is not really what I want).
>>>
>>> Is there another way?
>>>
>>> Cheers
>>> Leo
>>> _______________________________________________
>>> talk at x-query.com
>>> http://x-query.com/mailman/listinfo/talk
>>>
>>
>> _______________________________________________
>> talk at x-query.com
>> http://x-query.com/mailman/listinfo/talk
>>
>>
>>
>> _______________________________________________
>> talk at x-query.com
>> http://x-query.com/mailman/listinfo/talk
>>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
>
>
> _______________________________________________
> talk at x-query.com
> http://x-query.com/mailman/listinfo/talk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://x-query.com/pipermail/talk/attachments/20160605/fd8ff7ca/attachment.html>


More information about the talk mailing list