dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


advertisement
 

Learn Better Ways to Manage Data in ASP  : Page 2

Take advantage of XML and XSLT to display, manage, and cache data.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Transform XML with XSLT Stylesheets
As the list of links won't change terribly often, you could easily store them in a simple XML document. For example:

<?xml version="1.0"?> <menu> <nextid>4</nextid> <link id="link1" title="Link 1" url="http://myserver/someplace/file1.asp" /> <link id="link2" title="Link 2" url="http://myserver/someplace/file2.asp" /> <link id="link3" title="Link 3" url="http://myserver/someplace/file3.asp" /> <!-- etc --> </menu>

You can write an XSLT stylesheet to transform that data into HTML, for example:

<?xml version='1.0'?> <xsl:stylesheet xmlns:xsl= "http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="html"/> <xsl:template match="/"> <xsl:apply-templates select="menu"/> </xsl:template> <xsl:template match="menu"> <table align="left" width="150"> <xsl:apply-templates select="link"/> </table> </xsl:template> <xsl:template match="link"> <tr><td> <a href="{@url}"> <xsl:value-of select="@title"/> </a> </td></tr> </xsl:template> </xsl:stylesheet>

Then you can perform the transform on the server:



<%@ Language=VBScript %> <% dim xml dim xsl set xml = Server.CreateObject("MSXML2.DOMDocument.4.0") set xsl = Server.CreateObject("MSXML2.DOMDocument.4.0") xml.load Server.MapPath(".") & "\menu.xml" xsl.load Server.MapPath(".") & "\menu.xsl" %> <html> <head> </head> <body> <%Response.Write xml.transformNode(xsl)%> </body> </html>

Author's Note: For the code in this article, I've used the MSXML version 4 processor, but the code works fine with version 3. To use it with version 3, change every occurrence of Server.CreateObject("someobjectProgID.4.0") to Server.CreateObject("someobjectProgID.3.0").



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date