Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP and XHTML

Status
Not open for further replies.

emillen

Technical User
Joined
May 29, 2004
Messages
2
Location
CA
I build an ASP content management program for my site. About 50 users login and update news, events, stories and lots more. All my stories are in XHTML created by WYSIWYG editor. I store my XHTML in a database. My ASP pages read from database and then Response.Write the data. This is good.

But I want to change the data before I do Response.Write. Because XHTML is XML I think I can use DOM, XSLT and SAX. I have not done this from ASP, how do I do this. For example, I have a story in XHTML stored in the database that has five H2 tags. I want my ASP page to display the H2 tags at the top of the page like a table of contents in a story. How do I use ASP to do this?

Thank you so much,
E.
 
i'm guessing since you haven't had any responses yet, you might want to post a little "pseudo" stuff, like sample xhtml and sample converted xhtml
 
You could create a simple XSL sheet and then apply it to the string that you have received from the database. W3Schools has a lot of good information on using XSL for XML transformations: XSL at W3Schools.com

Here is a sample:
Code:
[b]SampleXHTML.html[/b]
<html>
<head>
<title> Sample XHTML Page </title>
</head>
<body>
<h2>A sample H2 Tag</h2>
<p>A sample paragrah. This is paragraph one.</p>
<h2>A second H2 Tag</h2>
<p>A second sample paragraph is contained here.</p>
</body>
</html>

[b]SampleXHTML.xsl[/b]
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0" xmlns:xsl="[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform">[/URL]

<xsl:template match="/">
	<html>
	<body>
		<h2>Story Sub-Sections</h2>
		<xsl:for-each select="//h2">
			Section: <xsl:value-of select="."/><br/>
		</xsl:for-each>
	</body>
	</html>
</xsl:template>

</xsl:stylesheet>

[b]SampleXHTML.asp[/b]
<%
Dim xml, xsl

'Load XML
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("SampleXHTML.html"))

'Load XSL
Set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("SampleXHTML.xsl"))

'Transform file
Response.Write(xml.transformNode(xsl))
%>

Another option would be to forgoe the XSL sheet altogether and simply use the built-in selectNodes method to get a collection of the h2 xml nodes, then output them in a for each loop in the ASP code:
Code:
[b]SampleXHTML.asp[/b]
<%
Dim xml, xsl

'Load XML
Set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("SampleXHTML.html"))

Response.Write xml.parseError.reason

'Grab the H2 tags - xpath //tagname
Dim h2_list, h2_item
Set h2_list = xml.selectNodes("//h2")
Response.Write "<html><body>SubSections: " & h2_list.length & " found.<br/>"
For Each h2_item in h2_list
	Response.Write "SubSection: " & h2_item.text & "<br/>"
Next
Response.Write "</body></html>"
%>

Hope this helps,

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top