Solved

Microsoft.XMLDOM to insert snipets of XHTML

Posted on 2004-09-03
3
994 Views
Last Modified: 2013-12-16
Hi everyone

I want ot know if this is possible. I want to insert setions of XHTML using ASP. I have a XML document:

<?xml version="1.0" encoding="ISO-8859-1"?>

<menu>
      <title>
            Business details
      </title>
      <title>
            Graduate vacancies
      </title>
      <title>
            Vacanacy work
      </title>
      <title>
            Events
      </title>
      <title>
            Staff details
      </title>
      <title>
            Business bridge
      </title>
      <title>
            Search
      </title>
</menu>

and a XSL document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <xsl:for-each select="menu">
      <tr>
            <td class="tblLeft_GV" valign="top" id="GVsym" width="10px">
                  +
            </td>
            <td id="GV" class="tblLeft_GV">
                  <A HREF="#" class="left"><xsl:value-of select="title"/></a>
            </td>
      </tr>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

and a ASP file with the code:

<table class="tblLeftmenu" cellpadding="0" cellspacing="0" border="0">
      <%
      'Load XML'
      set xml = Server.CreateObject("Microsoft.XMLDOM")
      xml.async = false
      xml.load(Server.MapPath("main.xml"))

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

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

At the moment I'm getting the an error message. Is this because you just cant do this, i.e. does all the HTML have to be in the XSL file and you cannot insert sections of HTML, or am I just doing something completly wrong?

Cheers in advance for your help

0
Comment
Question by:sonic1981
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
rdcpro earned 200 total points
ID: 11976987
No you can insert snippets of HTML using XSLT server side.  This:

   set xml = Server.CreateObject("Microsoft.XMLDOM")
 
may be what's causing the problem.  This is the old parser.  You want either:

Version 3.0:
   set xml = Server.CreateObject("Msxml2.DomDocument")

Version 4.0:
   set xml = Server.CreateObject("Msxml2.DomDocument.4.0")


If you have MSXML 3 in replace mode (SP1 or later), then this isn't probably what's causing your error, but change the code anyway.

You're also better off doing this:

  <% xml.transformNodeToObject(xsl, Response)) %>

note there is no use of Response.write.  This preserves encoding, and will cause fewer errors and problems.  Put the rest of your code at the top of the page, and only put that last little bit where you want the transformation to occur.

Also, if you really want iso-8859-1 (I prefer using UTF-8 for everything), modify the beginning of your XSLT like:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="html" version="1.0" encoding="iso-8859-1" indent="yes"/>


If you're still getting an error, post the error message.

Regards,
Mike Sharp
0
 
LVL 1

Author Comment

by:sonic1981
ID: 11988530
Hi

Thanks for the above help rdcpro. I have modified my code to as above but am still getting a error message. The message is:




msxml3.dll error '80004005'
The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document.

/testcode/bbtestfiles/cas/main2.asp, line 54

I reckon the problem is with the XSL stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
      <xsl:for-each select="menu">
      <tr>
            <td class="tblLeft_GV" valign="top" id="GVsym" width="10px">
                  +
            </td>
            <td id="GV" class="tblLeft_GV">
                  <A HREF="#" class="left"><xsl:value-of select="title"/></a>
            </td>
      </tr>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
 
 going to continue playing with it but any further help would be great.

 
0
 
LVL 1

Author Comment

by:sonic1981
ID: 11988676
Sorted it out, really simple problem in the end.

the xsl document wasn't well formed because the <a> tag was opened as <A HREF> and the close tag was </a>. To used to HTML!!
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question