Subject: Professional ASP XML Book
Posted By: codeurai Post Date: 1/8/2004 10:43:03 PM
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
Reply By: charul_shukla Reply Date: 1/9/2004 3:21:26 AM
Hi Joe,

Just a little typo error in the following line:

Response.Write(sHrml)

Please correct the variable name as follows

Response.Write(sHtml)

Charul Shukla

Reply By: codeurai Reply Date: 1/9/2004 7:50:20 AM
Well, don't I feel like an idiot now, lol

Thanks Charul

Go to topic 8250

Return to index page 972
Return to index page 971
Return to index page 970
Return to index page 969
Return to index page 968
Return to index page 967
Return to index page 966
Return to index page 965
Return to index page 964
Return to index page 963