SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: xml/asp

  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Location
    UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml/asp

    Hi,

    I am making my first foray intp xml via asp and xsl. I have adapted a script the I found at asp101 to my needs for this but I am getting errrors and cant see why. Obviously I am doing something wrong but I am puzzled. I know that the xml is well-formed and is parsed but the Required node is just not picked up fro some reason.
    I have posted all relevant docs in the zip in the hopes that someone can show me the error of my ways
    The DTD: (ddmenu.dtd)
    ========
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- edited with XML Spy v3.0.7 (http://www.xmlspy.com) by Keith 
    Parker (Diamond Designs) -->
    <!ELEMENT menus (menu+)>
    <!ELEMENT menu (item+)>
    <!ELEMENT item (ident+,parent+,page+,txt+)>
    <!ELEMENT ident (#PCDATA)>
    <!ELEMENT parent (#PCDATA)>
    <!ELEMENT page (#PCDATA)>
    <!ELEMENT txt (#PCDATA)>
    <!ATTLIST menus id CDATA #REQUIRED>
    <!ATTLIST menu id CDATA #REQUIRED parent CDATA #REQUIRED>
    The XML: (ref.xml)
    ========
    Code:
    <?xml version="1.0"?>
    <!-- edited with XML Spy v3.0.7 (http://www.xmlspy.com) by Keith 
    Parker (Diamond Designs) -->
    <!DOCTYPE menus SYSTEM "ddmenu.dtd">
    <menus id="root">
    <menu id="main" parent="root">
    <item>
    <ident>scripts</ident>
    <parent>main</parent>
    <page>scripts.xml</page>
    <txt>Scripts</txt>
    </item>
    <item>
    <ident>scriptingenvironments</ident>
    <parent>main</parent>
    <page>scriptingenvironments.xml</page>
    <txt>Scripting Environments</txt>
    </item>
    <item>
    <ident>stylesheets</ident>
    <parent>main</parent>
    <page>stylesheets.xml</page>
    <txt>Style Sheets</txt>
    </item>
    <item>
    <ident>markupdefinitionlanguages</ident>
    <parent>main</parent>
    <page>markupdefinitionlanguages.xml</page>
    <txt>Markup Definition Languages</txt>
    </item>
    <item>
    <ident>scripting</ident>
    <parent>main</parent>
    <page>scripting.xml</page>
    <txt>Scripting</txt>
    </item>
    <item>
    <ident>markuplanguages</ident>
    <parent>main</parent>
    <page>markuplanguages.xml</page>
    <txt>Markup Languages</txt>
    </item>
    <item>
    <ident>dom</ident>
    <parent>main</parent>
    <page>dom.xml</page>
    <txt>DOM</txt>
    </item>
    </menu>
    </menus>
    The XSL: (ref.xsl)
    ========
    Code:
    <?xml version="1.0">
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="menus/menu">
    <table cellpadding="0" cellspacing="0" border="0" 
    style="position:absolute;top:50px;left:20px;
    width:160px;">
    <xsl:for-each select="menu/item">
    <tr>
    <td id="mnucell" style="height:100%;width:180px;
    font-family:arial;font-size:10px;
    font-weight:500;color:#336666;
    border:1px solid #336666;padding:2px;
    cursor:hand;">
    <xsl:value-of select="txt"/>
    </td>
    </tr>
    </xsl:for-each>
    </table>
    </xsl:template>
    </xsl:stylesheet>
    The asp: (index.asp)
    ========
    Code:
    <%
    Option Explicit
    %>
    <%
    Dim objXSL
    Dim objNode
    Dim objXML
    Dim id
    id = "main"
    viewDetail server.MapPath("ref.xml"), server.MapPath("ref.xsl"), id
    %>
    <html>
    <head>
    <title>Loading a XML Document</title>
    <style type="text/css">
    #menublock{position:absolute;top:0px;
    left:-200px;height:100%;width:220px;
    z-index:1;text-align:center;
    padding-top:50px;background-color:#99cccc}
    #menut{width:180px;}
    #menu{width:100%;}
    #menubar{position:absolute;top:0px;left:200px;
    height:100%;width:20px;
    background-color:#cccc99;
    vertical-align:center;
    padding-top:250px}
    #pagediv{position:absolute;top:0px;left:20px;
    height:100%;width:780px;
    background-color:#cc99cc;z-index:0}
    </style>
    </head>
    <body scroll="no">
    <div id="menublock" onmouseover="this.style.left=0" 
    onmouseout="if(event.x > 20) this.style.left=-200">
    <table id="menut" border="0" cellpadding="0" 
    cellspacing="0"><tr><td id="menu">
    <%
    '--------------------------------------
    'This function accepts three paramters:
    'strXMLFile - The XML file that you wish to view
    'strXSLFile - The XSL stylesheet that will transform the XML file
    'strEMail - The E-Mail address of the contact that you wish to view
    '-------------------------------------------------------------------
    Function viewDetail(strXMLFile, strXSLFile, strEMail)
    'Declare local variables
    'Instantiate the XMLDOM Object that will hold the XML file.
    set objXML = Server.CreateObject("Microsoft.XMLDOM")
    'Turn off asyncronous file loading.
    objXML.async = false
    'Load the XML file.
    objXML.load(strXMLFile)
    'Get the XML record that you wish to view by calling the
    'SelectSingleNode method and passing in the e-mail address of the
    'contact.
    
    Set objNode = objXML.SelectSingleNode("menus/menu[item/ident='" & id 
    & "']")
    'Instantiate the XMLDOM Object that will hold the XSL file.
    set objXSL = Server.CreateObject("Microsoft.XMLDOM")
    'Turn off asyncronous file loading.
    objXSL.async = false
    'Load the XSL file.
    objXSL.load(strXSLFile)
    'Use the "transformNode" method of the XMLDOM to apply the XSL
    'stylesheet to the XML document. Then the output is written to the
    'client.
    Response.Write(objNode.transformNode(objXSL))
    End Function
    %>
    </td></tr></table>
    <div id="menubar"><img id="arrow" name="arrow" src="next.gif"
    border="0" height="15" width="15"></div>
    </div>
    <div id="pagediv"></div>
    </body>
    </html>
    Cheers,

    Keith

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    One problem I can see is that in the ASP code you're using the following query path, to get the node, where the variable id has the value 'main'.

    Code:
    menus/menu[item/ident='" & id & "']
    The trouble is you don't have any node that matches this path so the objNode object will not be set. When you later use this node it'll throw an error. You need to check the query path that you're using.

    Adding some code to check that you've got a valid node would also help.

    Code:
    ...
    Set objNode = objXML.SelectSingleNode("menus/menu[item/ident='" & id & "']")
    
    If (objNode Is Nothing) Then
    	'We got a problem
    	Response.Write "<p>Problem getting node.</p>"
    Else
    	'We got the node to do the transform
    
    	'Instantiate the XMLDOM Object that will hold the XSL file.
    	set objXSL = Server.CreateObject("Microsoft.XMLDOM")
    	
    	'Turn off asyncronous file loading.
    	objXSL.async = false
    	
    	'Load the XSL file.
    	objXSL.load(strXSLFile)
    	
    	'Use the "transformNode" method of the XMLDOM to apply the XSL
    	'stylesheet to the XML document. Then the output is written to the
    	'client.
    	Response.Write(objNode.transformNode(objXSL))
    	
    End If
    ...
    I also noticed that in altering the code you're no longer using the viewDetail function third parameter. You may want to change this param to the ID that you're passing in.


    I've only had a quick look through the code so if you have any problems I'll have a closer look.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •