This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: === Identifying a unique node in a DOM tree ===


I (.dan.) posted a while back...

> > Although you probably understand what I mean if I was to
> > indicate a path
> > like "http://my.xml.com/document.xml#/root/chapter/section",
> > the fact is
> > that that notation CANNOT work.
> 
Kevin Williams wrote:
>
> Only in the sense that a (hypothetical) construct like
> 
> c:/documents/root*/chapter*/section*
> 
> doesn't work.

That was my point exactly, it's those _implicit_ wildcards that I would
label a 'gotcha'.

> One of the
> nice things about XPointer (IMO) is that you can use it to point to more
> than one node

V. true! It is totally powerful for doing this job. It just 'thinks
different' if you're used to unique paths...
Coming from SQL, where every 'Select' returns an array, it's less of a
brain-strain.

And as for the question raised in this thread, the correct answer was
posted by

Khalid Asad
> If you have an xapth = '/doc/name[4]/@first'  you will get the 'first'
> attribute node of the 4th 'name' element. You can refer to this node to
> update the original document.

Which mimics the solution indicated in my original post:
> something like document.xml#/root[0]/chapter[1]/section[1]

So quite clearly it can be done!

From Johnathan's question
> is there an XML or DOM implementaion 
> that uniquely identifies a node? 

... well sure. My observation was just a caveat to do specifically with
XSLT, and most extant programatical implimentations have even more
control than my pseudo XPATH example. (ooOOoo big words...)

The later question :
> I want to be able to ask the node.."Who are you" and it would reply "I am
> currently /.people.person.name.John"

Relys on an external index. What do you mean by 'currently'? Is that a
variable, or something to do with the order of processing?
If your structure was 

<people>
  <person userid="55"><name>John</name><title>Mr</title></person>
  <person userid="66"><name>Jack</name><title>Sir</title></person> 
</people>

...It's trivial to use
<xsl:template match="person"><xsl:value-of select="name"
/></xsl:template>

OTOH, you can also construct a query for

<xsl:value-of select="/people/person/[@userid='55']/name" />

(there may be something wrong with that syntax)
... if you know which one you're trying to ID. Otherwise you use the
ordinal index.

... So Unique IDs are the other way to go. And very handy they are too.
That's why Cocoon1 presented me with such F***ed-up paths when it was
trying to id an XML node as an URL. Eventually I understood its
'wisdom'. 

.dan.


:=====================:====================:
: Dan Morrison        : The Web Limited    :
:  http://here.is/dan :  http://web.co.nz  :
:  dman@es.co.nz      :  danm@web.co.nz    :
:  04 384 1472        :  04 495 8250       :
:  025 207 1140       :                    :
:.....................:....................:
: If ignorance is bliss, why aren't more people happy?
:.........................................:


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]