SGML

Parameter Entities Examples

parameter-entities/expansion-in-decl
Shows that references to parameter entities get replaced in other parameter entities' literal replacement text
parameter-entities/expansion-in-decl1
Bariant of the example before using single quotes in place of double quotes, and vice-versa
parameter-entities/expansion-in-literal
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
Parameter entities can also be system-specific (ie. specified with just omitted system identifier literal)
parameter-entities/preexpansion-in-literal0
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
Note: To process SGML from the example sources, copy and paste an example source, store it into a file with the ".sgm" file extension, and invoke
sgmlproc <your-file.sgm>
where <your-file.sgm> is replaced by the actual file used for storing.

parameter-entities/expansion-in-decl

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

parameter-entities/expansion-in-decl1

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

parameter-entities/expansion-in-literal

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

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

parameter-entities/preexpansion-in-literal0

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