Suggestions

James Tauber jtauber at jtauber.com
Wed Apr 14 07:40:27 BST 1999


Scott Deboy wrote:
> 
> I'm new to XML (reading the spec and learning about DTDs etc.) and I was
> hoping someone could point me in the right direction on an idea I have to
> replace Word macros w/a 3-tier system using XML.
> 
> Example: I want to build a letter macro using XML.
> 
> The letter is mostly static text.  An address is required, as well as a
> couple of other fields.  Also, the letter has a couple of optional
> paragraphs that I need to prompt the user to answer.

A better approach would be to represent the user provided information as
an XML document which is then given to an XSL engine to add the static
text. So your template/macro would be a combination of a DTD
constraining user-provided information, and an XSL stylesheet that takes
that information and produces the output.

Here's a really simple example.

Say you are writing thank you notes for an engagement party.

For each person you have a document like:

<Person wedding="yes">
  <Name>John</Name>
  <Gift>vase</Gift>
</Person>

that indicates the person's name, what gift they gave and whether they
are coming to the wedding. Here's a DTD:

<!ELEMENT Person (Name,Gift)>
<!ATTLIST wedding (yes|no) #REQUIRED>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Gift (#PCDATA)>

You then have an XSL stylesheet with a template such as:

<xsl:template match="Person">
  <P>Dear <xsl:value-of select="Name"/>,</P>
  <P>Thank you so much for your <xsl:value-of select="Gift"/>.</P>
  <xsl:choose>
    <xsl:when test='.[wedding="yes"]'>
      <P>Look forward to seeing you at the wedding.</P>
    </xsl:when>
  <xsl:choose>
  <P>James</P>
</xsl:template>

Is this the sort of thing you wanted to do?

xml-dev: A list for W3C XML Developers. To post, mailto:xml-dev at ic.ac.uk
Archived as: http://www.lists.ic.ac.uk/hypermail/xml-dev/ and on CD-ROM/ISBN 981-02-3594-1
To (un)subscribe, mailto:majordomo at ic.ac.uk the following message;
(un)subscribe xml-dev
To subscribe to the digests, mailto:majordomo at ic.ac.uk the following message;
subscribe xml-dev-digest
List coordinator, Henry Rzepa (mailto:rzepa at ic.ac.uk)




More information about the Xml-dev mailing list