Solved

Microsoft.XMLDOM to insert snipets of XHTML

Posted on 2004-09-03
3
984 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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…
Objective of This Article In 1990’s, when I was a budding software professional, I had a lot of confusion about which stream or technology, I had to choose to build my career. In those days, I had lot of confusion like whether to choose System so…
The purpose of this video is to demonstrate how to connect a WordPress website to Google Analytics. This will be demonstrated using a Windows 8 PC Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php :…
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now