Solved

Microsoft.XMLDOM to insert snipets of XHTML

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
selectSingleNode in Access 2013 11 53
RSS Feed Parsing for Images 5 59
Challenge to XML Gurus, (XML link downloads blank data while data exists) 10 55
Grunt No Clean Targets 6 100
Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
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 update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
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…

932 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

19 Experts available now in Live!

Get 1:1 Help Now