Starting with XML
By Neil Williams2007-11-07
Adding custom data to the page
Applying an XML template
In the .xsl file, insert the following line in place of the entire tag that contains the data to be loaded from the XML file. e.g. for NAVIGATE, I removed the <li><a href="" title="">text</a></li> line in order to load customised settings for the href, title and text. Insert:
<xsl:apply-templates select="CODEHELP/NAVIGATE"/>
Make sure you specify the correct selection, replace CODEHELP/NAVIGATE with your main tag and the desired custom tag.
Now you need to create the template to use. At the end of the .xsl file, after the final </xsl:template> line add and customise the following extract from codehelp.xsl to match your requirements:
<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>
Note: The <a> tag is not left half open at the start (<a ). XML adds the attribute values inside the tag itself by matching the attribute with the value-of the XML data. To insert plain text, outside the tag, omit the xsl:attribute tags, as with the CLICK value.
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
