Re: Side-effects, state, internal references

Subject: Re: Side-effects, state, internal references
From: "Lisa Pease" <lisap@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 16 Apr 1998 09:14:23 -0700
-----Original Message-----
From: Michel Goossens <Michel.Goossens@xxxxxxx>
To: xsl-list@xxxxxxxxxxxxxxxx <xsl-list@xxxxxxxxxxxxxxxx>
Date: Thursday, April 16, 1998 8:11 AM
Subject: Side-effects, state, internal references


[...]

>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:
>
><scrap>
><head>
><prod><lhs><rhs>.....</prod>
></scrap>
><scrap>
><head>
><prod><lhs><rhs>..<rhs>...</prod>
></scrap>
><scrap>
><head>
><prodgroup>
><prod><lhs><rhs>.....</prod>
><prod><lhs><rhs>.....</prod>
><prod><lhs><rhs>.....</prod>
></scrap>
>
>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.
>


To get the number generated automatically, use inside the appropriate
element the following:

<eval>
childNumber(this)
</eval>

You can add the literal parentheses around the number in this manner:

<literal>(</literal>
<eval>
childNumber(this)
</eval>
<literal>)</literal>

>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'>
><head>Document</head>
><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>
></scrap>
>
>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
>question.


You can create a pattern that selects an element based on attribute value.
You might also look into the mode option for generating differing outputs.
I'm not sure what you're asking here exactly.




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


Current Thread