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
Solved

Microsoft.XMLDOM to insert snipets of XHTML

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i generate these XML with SimpleXML() 5 75
Column Spacing 3 92
XSLT XML 4 28
Powershell XML in variable 4 23
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

792 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