From: Donal K. Fellows on
On 3 Dec, 16:04, "tom.rmadilo" <tom.rmad...(a)gmail.com> wrote:
> So how do you set the default namespace? Is it just { ""
> my:default:namespace} in the selectNodesNamespaces list?

Experiment says no (for tdom 0.8.3 anyway). If you need to peek into a
namespaced document, you need to use namespaced names:

% package require tdom
0.8.3
% dom parse {<a xmlns="a" xmlns:b="b" b:c="d"/>} doc
domDoc0x10bbd0
% $doc selectNodes -namespaces {c a} {/c:a}
domNode0x10c080
% $doc selectNodes -namespaces {c a d b} {/c:a/@d:c}
{b:c d}
% $doc selectNodes -namespaces {"" a d b} {/a/@d:c}
% $doc selectNodes -namespaces {"" a} {/a}

Donal.
From: Alan Grunwald on
Donal K. Fellows wrote:
> On 3 Dec, 16:04, "tom.rmadilo" <tom.rmad...(a)gmail.com> wrote:
>> So how do you set the default namespace? Is it just { ""
>> my:default:namespace} in the selectNodesNamespaces list?
>
> Experiment says no (for tdom 0.8.3 anyway). If you need to peek into a
> namespaced document, you need to use namespaced names:
>
> % package require tdom
> 0.8.3
> % dom parse {<a xmlns="a" xmlns:b="b" b:c="d"/>} doc
> domDoc0x10bbd0
> % $doc selectNodes -namespaces {c a} {/c:a}
> domNode0x10c080
> % $doc selectNodes -namespaces {c a d b} {/c:a/@d:c}
> {b:c d}
> % $doc selectNodes -namespaces {"" a d b} {/a/@d:c}
> % $doc selectNodes -namespaces {"" a} {/a}
>
I think I started the thread "several weeks ago" that Tom mentioned.
Despite gentle prodding, no-one came back with a definitive "you can't
do it" answer at the time, and I came away with the impression
(confirmed by experiments such as Donal's) that you had to invent a
prefix for the default namespace and use it in the xpath expression a la

% set doc [dom parse {<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=windows-1252"/>
</head>
</html>}]
domDoc0x84b6158
% $doc selectNodes -namespaces {default http://www.w3.org/1999/xhtml}
default:html/default:head/default:meta
domNode0x84c8190

Alan
From: tom.rmadilo on
On Dec 3, 8:23 am, "Donal K. Fellows"
<donal.k.fell...(a)manchester.ac.uk> wrote:
> On 3 Dec, 16:04, "tom.rmadilo" <tom.rmad...(a)gmail.com> wrote:
>
> > So how do you set the default namespace? Is it just { ""
> > my:default:namespace} in the selectNodesNamespaces list?
>
> Experiment says no (for tdom 0.8.3 anyway). If you need to peek into a
> namespaced document, you need to use namespaced names:
>
>   % package require tdom
>   0.8.3
>   % dom parse {<a xmlns="a" xmlns:b="b" b:c="d"/>} doc
>   domDoc0x10bbd0
>   % $doc selectNodes -namespaces {c a} {/c:a}
>   domNode0x10c080
>   % $doc selectNodes -namespaces {c a d b} {/c:a/@d:c}
>   {b:c d}
>   % $doc selectNodes -namespaces {"" a d b} {/a/@d:c}
>   % $doc selectNodes -namespaces {"" a} {/a}

Shoot, I misread Rolf's final paragraph that the document's namespace
declarations don't work for the default namespace (which we knew) to
mean the previous steps do work. Wishful thinking.
From: Rolf Ade on
tom.rmadilo wrote:
>On Dec 3, 5:47�am, points...(a)gmx.net (Rolf Ade) wrote:
>> While Donal is right, lemme add, that you are able to set up the
>> prefix / namespace mapping used in selectNodes XPath expression once
>> for the whole document with
>>
>> $doc selectNodesNamespaces {
>> � � �prefix1http://aaa/whatever
>> � � �anotherhttp://bbb/whatever
>>
>> }
>>
>> After doing this, just use the defined prefixes in your XPath queries
>> without further need to use the -namespaces options:
>
>So how do you set the default namespace? Is it just { ""
>my:default:namespace} in the selectNodesNamespaces list?

No.

http://groups.google.com/group/comp.lang.tcl/msg/1c657d8bc233ffc9

for the how-to and

http://groups.google.com/group/comp.lang.tcl/msg/29c2169089892d8e

for a discussion. Both postings not even 4 weeks ago.

>Also, does this work with the xslt stuff? We had a question several
>weeks ago on how to deal with namespaced nodes using the default
>namespace.

With XSLT 1.0 you don't have to do anything about namespace resolution
but just write a working, correct XSLT document.

Just declare a prefix for any namespace, needed in the XPath
expressions in your XSLT transformation (declare it in the XSLT
document, that is). No need (nor any effect) of selectNodesNamespaces.

To put it more formally: Every XPath expression has two context
nodes. There is 'the' context node of the expression, that is the
starting point of any relative XPath expression. And there is the
'expression context node', used to resolve namespace prefixes.

While using XPath with a DOM tree, the context node and the expression
context node are always the same one: the node, you call the
selectNodes method on.

With an XSLT 1.0 transformation, there are two trees: the source tree
and the xslt tree. During an xslt transformation, there is always a
current node in the source tree. The xslt tree node, that works on
that current source tree node is the expression context node. XPath
prefix resolution for is done with the prefix/namespace declarations
in scope at the xslt node, the expression context.

rolf