blob: 43ad38f51a59c5cd45ca755ad2bb581603d0b2de [file] [log] [blame]
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="../org.eclipse.wst.doc.user/common.css" />
<title>Reusing the value of one entity in another entity</title>
</head>
<body id="trusents"><a name="trusents"><!-- --></a>
<h1 class="topictitle1">Reusing the value of one entity in another entity</h1>
<div><p>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.</p><div class="skipspace"><p>The following instructions were written for the
Resource perspective, but they will also work in many other perspectives. </p>
<p>You
can create an entity that reuses another entity. To do so, follow these steps:</p>
</div>
<ol><li class="skipspace"><span>Open your DTD in the DTD editor.</span></li>
<li class="skipspace"><span>Create an entity.</span> <ol type="a"><li><span>Type a name for the entity and select <span class="uicontrol">Parameter</span> from
the <span class="uicontrol">Entity type</span> list.</span></li>
<li><span>Type the value of the entity in the <span class="uicontrol">Entity Value</span> field.</span></li>
</ol>
</li>
<li class="skipspace"><span>Create another entity.</span><ol type="a"><li><span>Type a name and select <span class="uicontrol">General</span> from the <span class="uicontrol">Entity
type</span> list.</span></li>
<li><span>In the <span class="uicontrol">Entity Value</span> field, type a reference
to the first parameter entities' value (that is, type %<var class="varname">parmentityname</var>;)</span></li>
</ol>
</li>
</ol>
<div class="skipspace"><p>You now have two entities with the exact same value. </p>
</div>
<div class="skipspace">The following sample shows how you might create an entity that reuses
the value of another entity.<p>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.</p>
<ol><li>Open your DTD in the DTD editor.</li>
<li>Create an entity. In the <span class="uicontrol">Name</span> field, type <kbd class="userinput">CopyrightDate</kbd>.
Select <span class="uicontrol">Parameter</span> from the <span class="uicontrol">Entity type</span> list.
In the <span class="uicontrol">Entity Value</span>, type <kbd class="userinput">Copyright 2003</kbd>.</li>
<li>Create another entity. In the <span class="uicontrol">Name</span> field, type <kbd class="userinput">CompanyCopyright</kbd>.
Select <span class="uicontrol">General</span> from the <span class="uicontrol">Entity type</span> list.
In the<span class="uicontrol">Entity Value</span> field, type <kbd class="userinput">%CopyrightDate;
MyCompany Publishing</kbd>.</li>
</ol>
<p>Now, if you need to change the copyright date, you only need to do
so in one place, not two.</p>
<p> <b>Note</b>: Since you had to make the CopyrightDate
entity a <span class="uicontrol">Parameter</span> 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 <kbd class="userinput">XMLCopyrightDate</kbd> with
a value of <kbd class="userinput">%CopyrightDate;</kbd> and use it instead in the
XML file.</p>
<p>To use the entity in an XML document, you must use the ampersand <kbd class="userinput">&amp;</kbd> followed
by the name of the entity, and then end with the semi-colon <kbd class="userinput">;</kbd>.
So, in an XML document, if you were working with an even page, you would need
to put this:</p>
<p><kbd class="userinput">&amp;XMLCopyrightDate; </kbd></p>
<p> to
call the XMLCopyrightDate entity.  Remember, you cannot call the CopyrightDate
entity because you had to make it a <span class="uicontrol">Parameter</span> entity
in order to be able to reference it in the CompanyCopyright entity.</p>
<p>If
you were working with an odd page, you would need to put this:</p>
<p><kbd class="userinput">&amp;CompanyCopyright; </kbd></p>
<p> to
call the CompanyCopyright entity.</p>
</div>
</div>
<div>
<p>
<b class="parentlink">Parent topic:</b> <a href="../topics/tcretent.html" title="An entity is a shortcut used to represent complex strings or symbols that would otherwise be impossible, difficult or repetitive to include by hand.">Creating entities</a><br />
</p>
<p><b class="reltaskshd">Related tasks</b><br />
<a href="../topics/trusintp.html" title="Reusing parameter entities in attributes can save you a lot of time. If you have several elements using the exact same attribute, you only have to input the information once (into an entity).  ">Reusing internal parameter entities in an attribute name or type</a><br />
<a href="../topics/trusextp.html" title="Using an entity in a content model can save you time if you want to have the same information in several content models. You can create a DTD that references another DTD and then declares an element whose content model refers to a parameter entity created in another DTD.">Reusing external parameter entities in an element's content model</a><br />
</p>
</div><p>
(C) Copyright IBM Corporation 2000, 2005. All Rights Reserved.
</p>
</body>
</html>