Solved

Microsoft.XMLDOM to insert snipets of XHTML

Posted on 2004-09-03
3
996 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The purpose of this video is to demonstrate how to create a Printer Friendly PDF on a WordPress Page. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome Screenshot” Google Chrome Extension, and SmallPDF.com Log…
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…

695 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