[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Parameterized entities?

  • From: Marcus Reichardt <u123724@gmail.com>
  • To: Roger L Costello <costello@mitre.org>
  • Date: Thu, 16 Jun 2022 16:24:11 +0200

Re:  Parameterized entities?
FWIW, SGML has data attributes ie attributes declared on notations, and then defined in declarations of entities having those notations, such as

    <!NOTATION gif SYSTEM>
    <!ATTLIST #NOTATION gif
       width NUMBER #IMPLIED
       height NUMBER #IMPLIED>
    <!ENTITY mypic
      SYSTEM mypic.gif
      NDATA gif [ width=200 height=100 ]
      >

And while data entities can't be expanded in markup text, this mechanism can be used nevertheless for parametric macro expansion. In sgmljs.net, if the notation has or is derived from the public identifier for SGML, and is used/redefined in a link type, and used as eg #CONREF entity (ie not as entity reference but as value of an ENTITY attribute, though there are more powerful alternatives), this gives you a fully type-checked parametric macro expansion system called templating in sgmljs.net, where the "parameters"/data attribute values appear as predefined ("system specific") entities in the template document, the document element of the template must match (or is inferred from) the element on which the template entity is placed in the invocation context, and effective markup declarations are inherited and validated into the template processing context such that the result document is guaranteed to be parseable using the main (or effective output DTD when different from the base DTD in a pipeline of link processes).

There's even a standards-defined way to pickup data attributes from regular markup attributes rather than from ENTITY declarations and perform all kinds of ninja processing using HyTime DAFE, and it's fully supported by sgmljs.net SGML.

Ok I guess I put you XML heads are already well outside your comfort zone ;) but anyway if you want to read about the details with examples, and check it out yourself, see http://sgmljs.net/docs/templating.html .

Have fun,
Marcus
sgml.io

Am 16.06.2022 um 14:21 schrieb Roger L Costello <costello@mitre.org>:



Thank you David. It is a shame XML doesn’t support parameterized ENTITY’s.

 

I decided to write a simple preprocessor using the Flex lexical analyzer.  It converts the following “fake” ENTITY references:

 

    &file('ARPT.XML');

    &file('NAV.XML');

    &file('TRM.XML');

 

into these XSLT variable declarations:

 

    <xsl:variable name='ARPT.XML' select="doc('ARPT.XML')"/>

    <xsl:variable name='NAV.XML' select="doc('NAV.XML')"/>

    <xsl:variable name='TRM.XML' select="doc('TRM.XML')"/>

 

For those interested, the Flex lexical analyzer that I created is shown below. Here’s how I run it from a command line:

 

more sample.xsl | preprocess > result.xsl

 

Here is the preprocessor (Flex lexical analyzer). I am sure that a skilled C programmer could write much better C code (the stuff within braces below) to extract the filename. If you are a skilled C programmer and have suggestions for improvement, I would love to hear them!

 

%option noyywrap

%{

#include <string.h>

%}

%%

"&file('"[A-Z]+".XML');"           {

                                                           char replacement[20];

                                                           char *start = strstr(yytext, "'");

                                                           char *end   = strstr(yytext, ".");

                                                           int length = end - start - 1;

                                                           char *marker = start + 1;

                                                           int i;

                                                           for (i=0; i<length; i++)

                                                              replacement[i] = *marker++;

                                                           replacement[i]    = '\0';

                                                           fprintf(stdout, "<xsl:variable name='%s.XML' select=\"doc('%s.XML')\"/>", replacement, replacement);

                               }

%%

int main()

{yylex();}



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.