xsl-list
[Top] [All Lists]

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

2022-06-02 06:27:57
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(_at_)nwalsh(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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 doesn’t have entities in it, so the parser
expands them away. (In principle, the parser doesn’t have to, but the
result won’t work in XSLT if it doesn’t.)

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>…

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(_at_)nwalsh(_dot_)com>
https://nwalsh.com/

Why do politicians lie? Because it works.

--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--


<Prev in Thread] Current Thread [Next in Thread>