A Smattering of XML, XSL, and DTDs

R.S. Freedman (April 2000)


A Sample XML document

A "Well Formed" Extensible Markup Language document ANote.xml that conforms to the XML syntax rules.

<?xml version="1.0"?>
<body>Don't forget to buy another 300 IBM!</body>


A "Valid" XML document

A "Valid" XML document is a "Well Formed" XML document that conforms to the rules of a Document Type Definition (DTD). The following file MyNote.xml has a reference to a DTD MyNote.dtd and a link to a StyleSheet MyNote.xsl:

<?xml version="1.0" ?>
<!-- MyNote.xml: A Database in XML.       R.S. Freedman 6 December 1999 -->
<!-- Includes Document Type Definition (dtd) and html Style Sheet (xsl) -->
<!DOCTYPE Collection SYSTEM "MyNote.dtd">       
<?xml-stylesheet type="text/xsl" href="MyNote.xsl"?>
<!-- Here is the marked up Data: -->
<body> Don't forget to buy another 300 IBM!</body>



What the "Valid" XML document looks like in a Web Browser (see xsl file MyNote.xsl...)







The Message: Don't forget to buy another 300 IBM!


The Document Type Definition

The following is the DTD file -- MyNote.dtd -- that specifies rules for parsing the data "notes".

The DTD uses XML syntax and Standard Generalized Markup Language (SGML) semantics.

<!-- MyNote.dtd: Rules for the Database (Meta-Data) in XML. --> 

<!-- R.S. Freedman 6 December 1999 -->
<!-- MyNote.dtd: Checked with Tool http://www.pault.com/Xmltube/dtdgen.html -->
<!ELEMENT note (to,from,heading,body)>
<!-- A note has these 4 components -->
<!ELEMENT heading (#PCDATA)>



The XSL "Template"

The file containing the Extensible Style Language (XSL) really XML again! File MyNote.xsl specifies rules for "formatting" the data in html for Browser display.

<?xml version="1.0" ?>
<!-- MyNote.xsl: An XML Style Sheet to map MyNote.xml into html -->
<!-- R.S. Freedman 6 December 1999 -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">	<!-- match all of note -->
<html>				<!-- insert html tags  -->
<xsl:for-each select="note">
 <table border="2" bgcolor="yellow"> 
  <tr> <!-- insert table headings --> 
  <tr> <!-- get values from note-->
	<xsl:value-of select= "to"/>
	<xsl:value-of select="from"/>
	<xsl:value-of select="heading"/>
 <h2> TheMessage:
 <xsl:value-of select="body"/>
</xsl:for-each>   <!-- close all wffs -->


XML treats special characters in a manner similar to HTML to prevent ambiguity.  For example, instead of < you should use &gt; in your document.  Here are some other aliases:













XML also provides entity references to further disambiguate character data from markup data. For further information, see Selena Sol's Web Developer's tutorial.