SGML

Parameter Entities Examples

parameter-entities/expansion-in-decl.sgm
shows that references to parameter entities get replaced in other parameter entities' literal replacement text
parameter-entities/expansion-in-decl1.sgm
variant of the example before using single quotes in place of double quotes, and vice-versa
parameter-entities/expansion-in-literal.sgm
shows that parameter entities get replaced in general entities' literal replacement text, so it's possible to forward a parameter entity to a general entity
parameter-entities/pe-as-unspecified-system-id.sgm
parameter entities can also be system-specific (ie. specified with just omitted system identifier literal)
parameter-entities/preexpansion-in-literal0.sgm
note entity references in identifier literals (ie. within quotes) aren't recognized and don't get expanded; to create a system identifier from a parameter entity, a literal token including quotes must be created first, and then used in place of a system literal syntax portion
parameter-entities/doc.sgm parameter-entities/e.dtd parameter-entities/subdir/f.dtd parameter-entities/subdir/g.dtd

imports (via parameter entities) e.dtd, which imports subdir/f.dtd which imports subdir/g.dtd; subdir/g.dtd is referenced from subdir/f.dtd without "subdir/" prefix, showing that a parameter entity reference occuring where a markup declaration is expected, rather than as expanded string within a markup declaration, has a xml:base-like context flowing with it such that references are interpreted relative to eg. subdir/f.dtd rather than the top-level file doc.sgm

parameter-entities/expansion-in-decl.sgm

<!DOCTYPE test SYSTEM "test.dtd" [
	<!ENTITY % rplcmt "'replacement text'">
	<!ENTITY nonparaent %rplcmt;>
]>
<test>
&nonparaent;
</test>

parameter-entities/expansion-in-decl1.sgm

<!DOCTYPE test SYSTEM "test.dtd" [
	<!ENTITY % rplcmt '"replacement text"'>
	<!ENTITY nonparaent %rplcmt;>
]>
<test>
&nonparaent;
</test>

parameter-entities/expansion-in-literal.sgm

<!DOCTYPE test SYSTEM "test.dtd" [
	<!ENTITY % rplcmt "see if this gets replaced">
	<!ENTITY % torplc "replacement: '%rplcmt;'">
	<!ENTITY nonparaent "%torplc;">
]>
<test>
&nonparaent;
</test>

parameter-entities/pe-as-unspecified-system-id.sgm

<!DOCTYPE test [
	<!ENTITY % requestparm SYSTEM>
	<!ENTITY requestparm "%requestparm">
	<!ELEMENT test - - (#PCDATA)>
]>
<test></test>

parameter-entities/preexpansion-in-literal0.sgm

<!DOCTYPE test [
	<!ELEMENT test - - (#PCDATA)>
	<!ENTITY % p "path">
	<!ENTITY % f "file">
	<!ENTITY % pe "'%p/%f'">
	<!ENTITY sysid SYSTEM %pe>
]>
<test>&sysid;</test>

parameter-entities/doc.sgm

<!doctype test [
	<!entity % e system "e.dtd">
	%e;
]>
<test>bla</test>

parameter-entities/e.dtd

<!entity % f system "subdir/f.dtd">
%f;

parameter-entities/subdir/f.dtd

<!entity % g system "g.dtd">
%g;

parameter-entities/subdir/g.dtd

<!element test - - (#pcdata)>