Michael Raichelson: Portfolio — Code — XML, XSLT & ASP Navigation System

The portfolio of web, multimedia and interactive works by Michael Raichelson, a web and multimedia designer/developer living in Annapolis, MD

Skip to Navigation Skip to Content

Portfolio — Code — XML, XSLT & ASP Navigation System

Objective: To create an easily updated navigation system for use on a website hosted on a Microsoft IIS web server.

Solution: Build a system that stores core site navigation in an easily modified XML file then transforms that file as appropriate on page load.

Technologies Used: XML, XSLT, ASP (VBScript)

nav.xml

This is the XML file for the navigation, sections and subsections will be rendered in the order they are entered in.

<?xml version="1.0"?>
<navigation>
   <section>
      <name>Our Services</name>
      <url>/our_services/</url>
      <subsection>
         <name>Accounting Services</name>
         <url>/our_services/accounting.asp</url> 
      </subsection>
      <subsection>
         <name>Dog Walking</name>
         <url>/our_services/dogwalking.asp</url> 
      </subsection>
   </section>
   <section>
      <name>Our Partners</name>
      <url>/partners/</url>
   </section>
   <section>
      <name>About Us</name>
      <url>/about_us/</url>
      <subsection>
         <name>History</name>
         <url>/about_us/history.asp</url> 
      </subsection>
      <subsection>
         <name>Staff</name>
         <url>/about_us/staff.asp</url> 
      </subsection>
      <subsection>
         <name>Job Openings</name>
         <url>/about_us/jobs.asp</url> 
      </subsection>
   </section>
</navigation>

nav.xsl

XSLT transformation rules for converting nav.xml to HTML

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
   <xsl:template match="/">
      <xsl:apply-templates />
   </xsl:template>
   <xsl:template match="/navigation" mode="toc">   
      <xsl:for-each select="section">
         <a class="nav1">
            <xsl:attribute name="href">
               <xsl:value-of select="url" />
            </xsl:attribute>
            <xsl:value-of select="name" />
         </a>
         <xsl:for-each select="subsection">
            <a class="nav2">
               <xsl:attribute name="href">
                  <xsl:value-of select="url" />
               </xsl:attribute>
               <xsl:value-of select="name" />
            </a>
         </xsl:for-each>
      </xsl:for-each>
   </xsl:template>      
</xsl:stylesheet>

ASP code

This is the VisualBasic code to read the XML file and then apply the XSLT transformations to it.

<%
   Dim sourceFile = Server.MapPath("/xml/nav.xml")
   Dim styleFile = Server.MapPath("/xml/nav.xsl")
   set source = Server.CreateObject("Microsoft.XMLDOM")
   source.async = false
   source.load(sourceFile)
   set style = Server.CreateObject("Microsoft.XMLDOM")
   style.async = false
   style.load(styleFile)
   Response.Write source.transformNode(style)
%>