Side-effects, state, internal references

Subject: Side-effects, state, internal references
From: Michel Goossens <Michel.Goossens@xxxxxxx>
Date: Thu, 16 Apr 1998 16:59:39 +0200 (METDST)
I am trying to typeset the "scrap" elements of the XML spec (the
production rules represented inside a box). As I do not have access
to the DTD used for the xml spec, I extracted all material inside
<scrap>...</scrap> tags, made a little dtd, which is agreeable to
nsgmls, and then wrote an XSL stylesheet (using DSSSL core objects) to
allow me experiment with various output formats based on the xml input.

As I want to number the productions (which are marked up inside
a "prod" element, I thought about incrementing a global variable
(initialised to zero inside a <define-script>...</define-script>)
but that is explicitly forbidden by the XSL spec (section 7.2: Limited
Side-effects). As the "prod" elements are encapsulated inside various
"scrap" element and possible further "prodgroup" elements, I cannot 
see how to simply get at the sequence number of the "prod"s in the
global document by using built-in functions. 

The general structure is:


And I would like to get:

Header 1
(1) Production Rule 1
(2) Production Rule 2

Header i
(x) Production Rule x
(x+1) Production Rule x+1


Where the number between brackets is generated automatically.

A second more tricky problem is that several production rules
refer to each other, e.g., the XML spec has its first production 
defined using the lines:
<scrap lang='ebnf' id='document'>
<prod id='NT-document'><lhs>document</lhs>
<rhs><nt def='NT-prolog'>prolog</nt> 
<nt def='NT-element'>element</nt> 
<nt def='NT-Misc'>Misc</nt>*</rhs></prod>

where the <nt> tags have an attribute def= which refers to a
production rule where that element is defined. Thus, "prolog"
is defined in a production rule identified with the ID='NT-prolog'
attribute on a <prolog> tag much further down the source document:

<prod id='NT-prolog'>....</prod>

I would like to be able to generate different output formats
(HTML, rtf, TeX,...) and prepare several representations expressing
these links in various ways, e.g., by generating a <A .., which should
not be to difficult in HTML, but, in the case of rtf or TeX, by getting
hold of the production number (as I explained above) and then associating
this prod. nb. with its reference, thus we could get

(1) document :== prolog[22] element[39] Misc[27]

where the numbers between [..] are those of the productions which
define the terms in question. This probably needs two passes on the
source document, but as I cannot build anything in global space, I don't
see how I could associate elements via their attributes with information
I generate for one of the elements (the definition of the term) in

Any help would be greatly appreciated (I use xslj 0.4 with the latest
jade on NT to do my experiments). Thanks in advance.

Michel Goossens

 XSL-List info and archive:

Current Thread