Starting with XML
By Neil Williams2007-11-07
Where's the data?
Creating the first XML file.
Now create a simple text file with an .xml extension and insert the following start code:
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="codehelp.xsl"?>
Remember to specify your .xsl file in place of codehelp.xsl
The XML file only contains the tags you entered in the .xsl stylesheet. Start with your main tag, making sure all other tags are enclosed within it. Then include each tag, matching the layout you planned:
<CODEHELP>
<NAVIGATE>
<FILE>html.xml</FILE>
<DESC>All the HTML help your website needs</DESC>
<CLICK>HTML Index</CLICK>
</NAVIGATE>
</CODEHELP>
To get this sample .xml file to operate, try a cut down version of codehelp.xsl: (Reproduced here only for comparison. There is a link to the file itself on the next page.)
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<HEAD>
<title>Test</title>
</HEAD>
<BODY>
<div>
<ul>
<li><a href="anyfile.xml"
title="home page?">Your home page?</a></li>
<xsl:apply-templates select="CODEHELP/NAVIGATE" />
<li><a href="../links/index.html"
title="the mandatory link page">Links</a></li>
</ul>
</div>
</BODY>
</html>
</xsl:template>
<xsl:template match="CODEHELP/NAVIGATE">
<li>
<a>
<xsl:attribute name="href">
<xsl:value-of select="FILE"/>
</xsl:attribute>
<xsl:attribute name="title">
<xsl:value-of select="DESC"/>
</xsl:attribute>
<xsl:value-of select="CLICK"/>
</a>
</li>
</xsl:template>
</xsl:stylesheet>
Tutorial Pages:
» What is XML and why use it?
» The XML language syntax
» Converting an existing HTML site to XML
» Creating your XML stylesheet
» Adding custom data to the page
» Where's the data?
» The Test Files
Copyright © Neil Williams
