Reusing the value of one entity in another entity

Reusing the value of an entity in another entity can save you time in several ways. For example, if your value is long and complicated, it is much faster to simply reuse an entity than manually type in your value each time. As well, if the value changes, you only have to change it in one location.

The following instructions were written for the Resource perspective, but they will also work in many other perspectives. 

You can create an entity that reuses another entity. To do so, follow these steps:

  1. Open your DTD in the DTD editor.
  2. Create an entity.
    1. Type a name for the entity and select Parameter from the Entity type list.
    2. Type the value of the entity in the Entity Value field.
  3. Create another entity.
    1. Type a name and select General from the Entity type list.
    2. In the Entity Value field, type a reference to the first parameter entities' value (that is, type %parmentityname;)

You now have two entities with the exact same value.

The following sample shows how you might create an entity that reuses the value of another entity.

You need to place a copyright at the end of every page of a book. On even pages, you need to put "Copyright 2003" and on odd pages, you need to put "Copyright 2003. MyCompany Publishing." First you will declare an entity with the simpler value and then create an entity with the more complicated value.

  1. Open your DTD in the DTD editor.
  2. Create an entity. In the Name field, type CopyrightDate. Select Parameter from the Entity type list. In the Entity Value, type Copyright 2003.
  3. Create another entity. In the Name field, type CompanyCopyright. Select General from the Entity type list. In theEntity Value field, type %CopyrightDate; MyCompany Publishing.

Now, if you need to change the copyright date, you only need to do so in one place, not two.

Note: Since you had to make the CopyrightDate entity a Parameter entity in order to be able to reference it in the CompanyCopyright entity, you cannot use it in an XML file. You would have to create a third entity called XMLCopyrightDate with a value of %CopyrightDate; and use it instead in the XML file.

To use the entity in an XML document, you must use the ampersand & followed by the name of the entity, and then end with the semi-colon ;. So, in an XML document, if you were working with an even page, you would need to put this:

&XMLCopyrightDate;

to call the XMLCopyrightDate entity.  Remember, you cannot call the CopyrightDate entity because you had to make it a Parameter entity in order to be able to reference it in the CompanyCopyright entity.

If you were working with an odd page, you would need to put this:

&CompanyCopyright;

to call the CompanyCopyright entity.

Related tasks
Reusing internal parameter entities in an attribute name or type
Reusing external parameter entities in an element's content model

Feedback