Tying It All Together: XSLT
- To apply the concepts you have learned thus far.
Tying it all Together
Exercise: Transforming the Business Letter
This exercise has two parts.
- First, you will transform the TyingItTogether/Exercises/BusinessLetter.xml to an HTML document. You can make it look however you like.
- Second, you will transform TyingItTogether/Exercises/BusinessLetter2.xml into XML that's valid against TyingItTogether/Exercises/BusinessLetter.dtd, so that you can then apply the XSLT you created in step 1 to output the transformed TyingItTogether/Exercises/BusinessLetter2.xml.
Code Sample: TyingItTogetherXsl/Exercises/BusinessLetter.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE BusinessLetter SYSTEM "BusinessLetter.dtd">
<?xml-stylesheet type="text/xsl" href="BusinessLetter.xsl"?>
<BusinessLetter>
<Head>
<SendDate>November 29, 2005</SendDate>
<Recipient>
<Name Title="Mr.">
<FirstName>Joshua</FirstName>
<LastName>Lockwood</LastName>
</Name>
<Company>Lockwood & Lockwood</Company>
<Address>
<Street>291 Broadway Ave.</Street>
<City>New York</City>
<State>NY</State>
<Zip>10007</Zip>
<Country>United States</Country>
</Address>
</Recipient>
</Head>
<Body>
<List>
<Heading>
Along with this letter, I have enclosed the following items:
</Heading>
<ListItem>two original, execution copies of the Webucator
Master Services Agreement</ListItem>
<ListItem>two original, execution copies of the Webucator
Premier Support for Developers Services Description between
Lockwood & Lockwood and Webucator, Inc.</ListItem>
</List>
<Para>Please sign and return all four original, execution copies to
me at your earliest convenience. Upon receipt of the executed copies,
we will immediately return a fully executed, original copy of both
agreements to you.</Para>
<Para>Please send all four original execution copies to my attention as follows:
<Person>
<Name>
<FirstName>Bill </FirstName>
<LastName>Smith</LastName>
</Name>
<Address>
<Company>Webucator, Inc.</Company>
<Street>4933 Jamesville Rd.</Street>
<City>Jamesville</City>
<State>NY</State>
<Zip>13078</Zip>
<Country>USA</Country>
</Address>
</Person>
</Para>
<Para>If you have any questions, feel free to call me at
<Phone>800-555-1000 x123</Phone> or e-mail me at
<Email>bsmith@webucator.com</Email>.</Para>
</Body>
<Foot>
<Closing>
<Name>
<FirstName>Bill </FirstName>
<LastName>Smith</LastName>
</Name>
<JobTitle>VP, Operations</JobTitle>
</Closing>
</Foot>
</BusinessLetter>
Code Sample: TyingItTogetherXsl/Exercises/BusinessLetter2.xml
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="Letter2Letter.xsl"?>
<Letter>
<Date>November 29, 2005</Date>
<To>
<Name>
<Title>Mr.</Title>
<FName>Joshua</FName>
<LName>Lockwood</LName>
</Name>
<Company>Lockwood & Lockwood</Company>
<Address>
<Street>291 Broadway Ave.</Street>
<City>New York</City>
<State>NY</State>
<Zip>10007</Zip>
<Country>United States</Country>
</Address>
</To>
<List>
<ListHead>
Along with this letter, I have enclosed the following items:
</ListHead>
<LI>two original, execution copies of the Webucator Master
Services Agreement</LI>
<LI>two original, execution copies of the Webucator Premier
Support for Developers Services Description between Lockwood
& Lockwood and Webucator, Inc.</LI>
</List>
<P>Please sign and return all four original, execution copies to me at
your earliest convenience. Upon receipt of the executed copies, we
will immediately return a fully executed, original copy of both
agreements to you.</P>
<P>Please send all four original, execution copies to my attention as
follows:
<Person>
<Name>
<FName>Bill </FName>
<LName>Smith</LName>
</Name>
<Address>
<Company>Webucator, Inc.</Company>
<Street>4933 Jamesville Rd.</Street>
<City>Jamesville</City>
<State>NY</State>
<Zip>13078</Zip>
<Country>USA</Country>
</Address>
</Person>
</P>
<P>If you have any questions, feel free to call me at
<Phone>800-555-1000 x123</Phone> or e-mail me at
<Email>bsmith@webucator.com</Email>.</P>
<End>
<Name>
<FName>Bill </FName>
<LName>Smith</LName>
</Name>
<Title>VP, Operations</Title>
</End>
</Letter>
Code Sample: TyingItTogetherXsl/Exercises/BusinessLetter.dtd
<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT Address (Company?, Street, City, State, Zip, Country)> <!ELEMENT Body (List, Para+)> <!ELEMENT BusinessLetter (Head, Body, Foot)> <!ELEMENT City (#PCDATA)> <!ELEMENT Closing (Name, JobTitle)> <!ELEMENT Company (#PCDATA)> <!ELEMENT Country (#PCDATA)> <!ELEMENT Email (#PCDATA)> <!ELEMENT FirstName (#PCDATA)> <!ELEMENT Foot (Closing)> <!ELEMENT Head (SendDate, Recipient)> <!ELEMENT Heading (#PCDATA)> <!ELEMENT JobTitle (#PCDATA)> <!ELEMENT LastName (#PCDATA)> <!ELEMENT List (Heading, ListItem+)> <!ELEMENT ListItem (#PCDATA)> <!ELEMENT Name (FirstName, LastName)> <!ATTLIST Name Title CDATA #IMPLIED > <!ELEMENT Para (#PCDATA | Person | Email | Phone)*> <!ELEMENT Person (Name, Address)> <!ELEMENT Phone (#PCDATA)> <!ELEMENT Recipient (Name, Company, Address)> <!ELEMENT SendDate (#PCDATA)> <!ELEMENT State (#PCDATA)> <!ELEMENT Street (#PCDATA)> <!ELEMENT Zip (#PCDATA)>
Tying It All Together: XSLT Conclusion
Congratulations! You have come a long way.