These pages are now out-of-date

Bookmarks / SGML exegeses / Kimber - Finding the root element

[Help] [Root] [Up] [Prev] [Next]

Kimber - Finding the root element

From eliot@dns.isogen.com Fri Oct 30 10:09:19 1998
Date: Thu, 29 Oct 1998 07:24:44 -0600
From: W. Eliot Kimber <eliot@dns.isogen.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Cc: Norman Walsh <ndw@nwalsh.com>
Subject: Re: Finding the root element

At 07:38 AM 10/29/98 -0500, Norman Walsh wrote:
>Apologies if I asked this once before...
>
>Is it possible to find the node of the document element outside
>the context of another element?  Specifically, can I find it in
>a function called from (root)?

This should work from any node in the grove:

(define (docelem node)
  (node-propety 'document-element 
    (node-property 'grove-root node)))

Cheers,

E.
--
<Address HyTime=bibloc>
W. Eliot Kimber, Senior Consulting SGML Engineer
ISOGEN International Corp.
2200 N. Lamar St., Suite 230, Dallas, TX 75202.  214.953.0004
www.isogen.com
</Address>


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From ndw@nwalsh.com Fri Oct 30 10:09:35 1998
Date: Thu, 29 Oct 1998 08:37:07 -0500
From: Norman Walsh <ndw@nwalsh.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

/ "W. Eliot Kimber" <eliot@dns.isogen.com> was heard to say:
| At 07:38 AM 10/29/98 -0500, Norman Walsh wrote:
| >Apologies if I asked this once before...
| >
| >Is it possible to find the node of the document element outside
| >the context of another element?  Specifically, can I find it in
| >a function called from (root)?
| 
| This should work from any node in the grove:
| 
| (define (docelem node)
|   (node-propety 'document-element 
|     (node-property 'grove-root node)))

Yes, but in (root ...) there's no (current-node), so how do I get 'node'?

                                        Cheers,
                                          norm
-- 
Norman Walsh <ndw@nwalsh.com>      | Clones are people two.
http://nwalsh.com/                 | 


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From dspeck@bna.com Fri Oct 30 10:09:41 1998
Date: Thu, 29 Oct 1998 08:45:19 -0500
From: Daniel Speck <dspeck@bna.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

W. Eliot Kimber wrote:

> At 07:38 AM 10/29/98 -0500, Norman Walsh wrote:
> >Apologies if I asked this once before...
> >
> >Is it possible to find the node of the document element outside
> >the context of another element?  Specifically, can I find it in
> >a function called from (root)?
>
> This should work from any node in the grove:
>
> (define (docelem node)
>   (node-propety 'document-element
>     (node-property 'grove-root node)))
>

So with what argument what do you call this function in the (root ...)
construction rule? (current-node) isn't defined in the root construction
rule. (process-children) is defined in the standard such that it behaves
differently (or the definition of "children" is different, I'm not sure
which) in the (root ...) construction rule. I've had this problem myself
and I usually just end up looking for the document element while processing
some element. Any ideas?

-dan

--
Daniel Speck
Bureau of National Affairs, Inc.               Voice: +1 202.452.6596
1231 25th Street, NW                             Fax: +1 202.331.5178
Washington, DC 20037                          e-mail:  dspeck@bna.com



 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From ht@cogsci.ed.ac.uk Fri Oct 30 10:09:47 1998
Date: 29 Oct 1998 15:32:22 +0000
From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

Daniel Speck <dspeck@bna.com> writes:

> W. Eliot Kimber wrote:
> 
> > At 07:38 AM 10/29/98 -0500, Norman Walsh wrote:
> > >Apologies if I asked this once before...
> > >
> > >Is it possible to find the node of the document element outside
> > >the context of another element?  Specifically, can I find it in
> > >a function called from (root)?
> >
> > This should work from any node in the grove:
> >
> > (define (docelem node)
> >   (node-propety 'document-element
> >     (node-property 'grove-root node)))
> >
> 
> So with what argument what do you call this function in the (root ...)
> construction rule? (current-node) isn't defined in the root construction
> rule. (process-children) is defined in the standard such that it behaves
> differently (or the definition of "children" is different, I'm not sure
> which) in the (root ...) construction rule. I've had this problem myself
> and I usually just end up looking for the document element while processing
> some element. Any ideas?
> 
Actually, undocumented feature of Jade is that (current-node) does in fact
return the root inside a root rule.  So the following works:

(root
 (literal
  (debug (node-property 'gi
          (node-property 'document-element (current-node))))))

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From gkholman@canadamail.com Fri Oct 30 10:09:55 1998
Date: Thu, 29 Oct 1998 10:30:10 -0500
From: G. Ken Holman <gkholman@canadamail.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

At 98/10/29 08:37 -0500, Norman Walsh wrote:
>Yes, but in (root ...) there's no (current-node), so how do I get 'node'?

Actually, for (root) there is a current node ... see below.

...... Ken


T:\dsssl>type test.sgm
<!DOCTYPE doc [
<!ELEMENT doc - O ( this )>
<!ELEMENT this - O ( that )>
<!ELEMENT that - O ( #pcdata )>
]><doc>
<this>
<that>that stuff
</doc>

T:\dsssl>type test.dsl
<!DOCTYPE style-sheet PUBLIC "-//James Clark//DTD DSSSL Style Sheet//EN">

(root
    (process-node-list
        (select-elements
            (children                       ;the children of
                (children                   ;the children of
                    (node-property          ;the document element
                        'docelem
                        (current-node))))
            "THAT")))
                    
(element that
    (process-children))

(element doc            ;avoid default behaviour looking correct
    (empty-sosofo))
    
;end of file

T:\dsssl>jade -c p:\jade\jadecurr\catalog test.sgm

T:\dsssl>type test.fot
<?xml version="1.0"?>
<fot>
<a name="2"/>
<text>that stuff</text>
</fot>

T:\dsssl>



--
G. Ken Holman               mailto:gkholman@CanadaMail.com
Crane Softwrights Ltd.  http://www.CraneSoftwrights.com/d/
Box 266,                                V: +1(613)489-0999
Kars, Ontario CANADA K0A-2E0            F: +1(613)489-0995
Training:   http://www.CraneSoftwrights.com/d/schedule.htm
Resources: http://www.CraneSoftwrights.com/d/resources.htm
Shareware: http://www.CraneSoftwrights.com/d/shareware.htm


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From ht@cogsci.ed.ac.uk Fri Oct 30 10:10:00 1998
Date: 29 Oct 1998 17:11:14 +0000
From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

"G. Ken Holman" <gkholman@CanadaMail.com> writes:

> At 98/10/29 15:32 +0000, Henry S. Thompson wrote:
> >Actually, undocumented feature of Jade is that (current-node) does in fact
> >return the root inside a root rule.  
> 
> Is that Jade-specific or DSSSL standard?  I assumed the description
> relating to "SDQL context" meant that "in the context of root,
> (current-node) returns the root node" ... but now that I look deeper into
> the spec, I can't find justification for that.
> 

Indeed a thorough search of the electronic original reveals that there 
are several gaps in the spec. wrt what the values are of
(current-node) and (current-root) in various contexts, most notably
for our purposes when the context is (root ...).  It certainly seems
reasonable that (current-node) should be DEFINED to be equivalent to
(current-root) in the root-construction-rule context.

A quick scan of the draft corrigenda doesn't reveal any attempt fill
these gaps either -- James?

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From ndw@nwalsh.com Fri Oct 30 10:10:05 1998
Date: Thu, 29 Oct 1998 12:48:41 -0500
From: Norman Walsh <ndw@nwalsh.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Cc: Norman Walsh <ndw@nwalsh.com>
Subject: Re: Finding the root element

| Actually, undocumented feature of Jade is that (current-node) does in fact
| return the root inside a root rule.  So the following works:
| 
| (root
|  (literal
|   (debug (node-property 'gi
|           (node-property 'document-element (current-node))))))

Right you are.  Thanks, Henry.  I swear I got an error once
about current-node being undefined in root, which is why I've
lept through all sorts of hurdles to get around the problem.
I must have misinterpreted an error message...

                                        Cheers,
                                          norm
-- 
Norman Walsh <ndw@nwalsh.com>      | Everything the same; everything
http://nwalsh.com/                 | distinct.


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From eliot@dns.isogen.com Fri Oct 30 10:10:10 1998
Date: Thu, 29 Oct 1998 11:33:54 -0600
From: W. Eliot Kimber <eliot@dns.isogen.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

At 10:58 AM 10/29/98 -0500, G. Ken Holman wrote:
>At 98/10/29 15:32 +0000, Henry S. Thompson wrote:
>>Actually, undocumented feature of Jade is that (current-node) does in fact
>>return the root inside a root rule.  
>
>Is that Jade-specific or DSSSL standard?  I assumed the description
>relating to "SDQL context" meant that "in the context of root,
>(current-node) returns the root node" ... but now that I look deeper into
>the spec, I can't find justification for that.

How could root rules be useful if you didn't have the grove root available?
If the standard as published doesn't provide for it, then the standard is
broken and needs to be fixed. 

Cheers,

E.
--
<Address HyTime=bibloc>
W. Eliot Kimber, Senior Consulting SGML Engineer
ISOGEN International Corp.
2200 N. Lamar St., Suite 230, Dallas, TX 75202.  214.953.0004
www.isogen.com
</Address>


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From ht@cogsci.ed.ac.uk Wed Nov  4 11:53:10 1998
Date: 30 Oct 1998 10:17:36 +0000
From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

"W. Eliot Kimber" <eliot@dns.isogen.com> writes:

> How could root rules be useful if you didn't have the grove root available?
> If the standard as published doesn't provide for it, then the standard is
> broken and needs to be fixed. 

I think Norm never mentioned the key point here:  The DSSSL standard
provides (current-root), which clearly would provide the needed node
within (root ...) or elsewhere.  It happens that Jade doesn't
include this procedure in the subset of DSSSL it implements, hence
Norm's problem.

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From eliot@dns.isogen.com Wed Nov  4 11:53:10 1998
Date: Fri, 30 Oct 1998 11:36:33 -0600
From: W. Eliot Kimber <eliot@dns.isogen.com>
Reply-To: dssslist@mulberrytech.com
To: dssslist@mulberrytech.com
Subject: Re: Finding the root element

At 10:17 AM 10/30/98 +0000, Henry S. Thompson wrote:
>"W. Eliot Kimber" <eliot@dns.isogen.com> writes:
>
>> How could root rules be useful if you didn't have the grove root available?
>> If the standard as published doesn't provide for it, then the standard is
>> broken and needs to be fixed. 
>
>I think Norm never mentioned the key point here:  The DSSSL standard
>provides (current-root), which clearly would provide the needed node
>within (root ...) or elsewhere.  It happens that Jade doesn't
>include this procedure in the subset of DSSSL it implements, hence
>Norm's problem.

Ah.

Still, I think it is logical that current-node should be the grove root in
a root rule.

Cheers,

E.

--
<Address HyTime=bibloc>
W. Eliot Kimber, Senior Consulting SGML Engineer
ISOGEN International Corp.
2200 N. Lamar St., Suite 230, Dallas, TX 75202.  214.953.0004
www.isogen.com
</Address>


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
From greynolds@datalogics.com Wed Nov  4 11:53:10 1998
Date: Fri, 30 Oct 1998 13:38:05 -0600
From: "Reynolds, Gregg" <greynolds@datalogics.com>
Reply-To: dssslist@mulberrytech.com
To: "'dssslist@mulberrytech.com'" <dssslist@mulberrytech.com>
Subject: RE: Finding the root element

Probably you encountered a problem when trying to use (current-node) to
get at the document element directly, which is problem that crops up
regularly.  Since (current-node) is so commonly used to get at nodes of
type element, the natural question is "why can't I use it for the root
element"; but the production (172, p 176 or thereabouts) says "A
root-construction-rule matches any node of class sgml-document".  That
class is defined to have a 'docelem' property whose value is of type
element.  (see definition of psmodule 'instabs', p 90).  So actually, it
would be inaccurate (if my understanding is correct) to say that
(current-node) returns the root; it looks to me like it behaves exactly
as specified.  Where I think the standard could use some clarification
is in the definition of (current-node); rather than "the semantics of
this are defined by the context..." it might say something like "the
class of the node returned depends on contenxt...".

Your original question was: 
"Is it possible to find the node of the document element outside the
context of another element? Specifically, can I find it in a function
called from (root)?"

Since the grove root is by definition the only node that does not appear
as the value of any subnode property of any node, and since the sgmldoc
node is the only node (that I know of) that fits that description, one
should be able to get the same effect by using the 'grovroot' intrinsic
property from any node, regardless of its class:

	(node-property 'property-appropriate-to-class-of-snl
	  (node-property 'document-element
	    (node-property 'grove-root snl)))

At least I think so.  I have not tested it.  (Instrinsic properties are
defined in section 9.4.)

A question I have is, why is the meaning of (current-root) context
dependent?  Presumably this comes into play in hypergroves?  Or subdocs?
I infer it would be possible for node a to have a property of type
urefnode, such that a value of that property, say node b, has a
different grove-root than does node a.  Accurate?

-----Original Message-----
From: Norman Walsh [mailto:ndw@nwalsh.com]
Sent: Thursday, October 29, 1998 11:49 AM
To: dssslist@mulberrytech.com
Cc: Norman Walsh
Subject: Re: Finding the root element


| Actually, undocumented feature of Jade is that (current-node) does in
fact
| return the root inside a root rule.  So the following works:
| 
| (root
|  (literal
|   (debug (node-property 'gi
|           (node-property 'document-element (current-node))))))

Right you are.  Thanks, Henry.  I swear I got an error once
about current-node being undefined in root, which is why I've
lept through all sorts of hurdles to get around the problem.
I must have misinterpreted an error message...

                                        Cheers,
                                          norm
-- 
Norman Walsh <ndw@nwalsh.com>      | Everything the same; everything
http://nwalsh.com/                 | distinct.


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist


 DSSSList info and archive:  http://www.mulberrytech.com/dsssl/dssslist
[Onward]
Norman
1 January 2001