Professional ASP XML Book
I am trying to learn xml/xsl using wrox's Professional ASP XML book.
I am having trouble in chapter 8 trying to perform transformations.
Here is my code:
[XML]
<?xml version="1.0" encoding="utf-8" ?>
<contact_info>
<business>
<contact>
<name>Jon Doe</name>
<phone>555-5319</phone>
</contact>
</business>
<personal>
<contact relation="family">
<name>Mary Jones</name>
<phone>555-9013</phone>
</contact>
<contact>
<name>Mike Wilson</name>
<phone>555-4138</phone>
</contact>
</personal>
</contact_info>
[XSL]
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="/contact_info">
<html>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="contact_info">
<xsl:for-each select="./*">
<xsl:choose>
<xsl:when test=".[.!nodeName()='personal']">
<div style="background-color:teal; color:white; font-family:verdana, arial; font-size:12pt; padding:2px;">Personal Contacts</div>
</xsl:when>
<xsl:otherwise>
<div style="background-color:black; color:white; font-family:verdana, arial; font-size:12pt; padding:2px;">Business Contacts</div>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates />
<p />
</xsl:for-each>
</xsl:template>
<xsl:template match="contact">
<xsl:for-each select=".">
<div>
<xsl:if test="@relation[.!value()='family']">
<xsl:attribute name="style">font-weight:bold;</xsl:attribute>
</xsl:if>
<xsl:value-of select="name" />
<div style="font-size:10pt; left:.25cm; position:relative;">
<xsl:value-of select="phone" />
</div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
[VBS]
<%@ Language="VBSCRIPT"%>
<%
Dim pDoc, pStyle, sHtml
Set pDoc = Server.CreateObject("Microsoft.XmlDom")
Set pStyle = Server.CreateObject("Microsoft.XmlDom")
If Not pDoc Is Nothing And Not pStyle Is Nothing Then
pDoc.async = False
pStyle.async = False
pDoc.Load(Server.MapPath("Contacts.xml"))
pStyle.Load(Server.MapPath("Contacts.xslt"))
If Not pDoc.parseError And Not pStyle.parseError Then
sHtml = pDoc.transformNode(pStyle)
Response.Write(sHrml)
Else
Response.Write("Parser error")
End If
Else
Response.Write("Error creating Xml objects")
End If
%>
When the transformation takes place, not html is returned, any ideas why?
Thanks
Joe
|