Re: [xsl] Why aren't ENTITY declarations in a main stylesheet visible in the included stylesheets?

Subject: Re: [xsl] Why aren't ENTITY declarations in a main stylesheet visible in the included stylesheets?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 2 Jun 2022 11:27:53 -0000
I've always thought it would be nice to have a mode of operation where the XML
can contain entity references, but the expansions are supplied by the
application using the parser API, rather than having to be present in the DTD.
That would open up lots of interesting possibilities, like a version of the
doc() function that constructs a parameterised document.

Michael Kay
Saxonica

> On 2 Jun 2022, at 12:20, Norm Tovey-Walsh ndw@xxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> I thought that an xs:include is essentially a "macro substitution", in
>> which case the entity declaration should be visible, yes?
>
> Nope. The XPath data model doesnbt have entities in it, so the parser
> expands them away. (In principle, the parser doesnbt have to, but the
> result wonbt work in XSLT if it doesnbt.)
>
>> I don't want to have ENTITY declarations scattered around multiple
>> files. What's the best way to deal with ENTITIES?
>
> If all your tooling will read the external subset, you can do something
> like this:
>
> <!DOCTYPE whatever SYSTEM "whatever.dtd" [
> <!ENTITY % myDecls SYSTEM "decl.ent">
> %myDecls;
> ]>
> <whatever>
> &spoon;
> </whatever>
>
> where decl.ent contains the entities, for example:
>
> <!ENTITY spoon "Spoon!">
>
> You can get them into your XSLT that way too:
>
> <!DOCTYPE xsl:stylesheet [
> <!ENTITY % myDecls SYSTEM "decl.ent">
> %myDecls;
> ]>
> <xsl:stylesheet>b&
>
> But you have to do that in every file (including the ones you include or
> import).
>
> See also this note from ~20 years ago:
>
>  https://norman.walsh.name/2003/09/27/dtds
>
> :-)
>
>                                        Be seeing you,
>                                          norm
>
> --
> Norman Tovey-Walsh <ndw@xxxxxxxxxx>
> https://nwalsh.com/
>
>> Why do politicians lie? Because it works.

Current Thread