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();} |