Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 11th, 2008, 12:56 AM
Authorized User
 
Join Date: Jun 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Unable to show XML using XSLT

Hello

I have a problem using XSLT..I want to show my XML file using XSLT.
But, it does not work. Here is my XML file (description2.xml):

<form>
    <description>
        <desc_id>048/26/SMD/HRD/9/00</desc_id>
        <title>Kebijakan2</title>
        <dates>3/21/1999</dates>
        <author>Smart Co</author>
        <file_name>Policy2</file_name>
        <type>pdf</type>
        <category>memorandum</category>
        <sub_cat1>tidak_berlaku</sub_cat1>
        <sub_cat2>1983</sub_cat2>
    </description>
</form>

Here is my XSL file(description2.xsl):
<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>Document Description</h2>
    <table border="1">
    <tr bgcolor="#9acd32">
      <th align="left">No. Surat</th>
      <th align="left">Title</th>
      <th align="left">Date</th>
      <th align="left">Author</th>
      <th align="left">File Name</th>
      <th align="left">File Type</th>
      <th align="left">Status</th>
      <th align="left">Year</th>
    </tr>
    <xsl:for-each select="form/description">
    <tr>
    <td><xsl:value-of select="desc_id"/></td>
    <td><xsl:value-of select="title"/></td>
    <td><xsl:value-of select="dates"/></td>
    <td><xsl:value-of select="author"/></td>
    <td><xsl:value-of select="file_name"/></td>
    <td><xsl:value-of select="type"/></td>
    <td><xsl:value-of select="sub_cat1"/></td>
    <td><xsl:value-of select="sub_cat2"/></td>
    </tr>
    </xsl:for-each>
    </table>
  </body>
  </html>
</xsl:template>

</xsl:stylesheet>

Here is my ASP code to load XML and XSL(show_xsl.asp):
<html>
<head>
<script>
function loadXMLDoc(fname)
{
var xmlDoc;
// code for IE
if (window.ActiveXObject)
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
  {
  xmlDoc=document.implementation.createDocument(""," ",null);
  }
else
  {
  alert('Your browser cannot handle this script');
  }
xmlDoc.async=false;
xmlDoc.load(fname);
return(xmlDoc);
}

function displayResult()
{
xml=loadXMLDoc("description2.xml");
xsl=loadXMLDoc("description2.xsl");
// code for IE
if (window.ActiveXObject)
  {
  ex=xml.transformNode(xsl);
  document.getElementById("example").innerHTML=ex;
  }
// code for Mozilla, Firefox, Opera, etc.
else if (document.implementation
&& document.implementation.createDocument)
  {
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  document.getElementById("example").appendChild(res ultDocument);
  }
}
</script>
</head>
<body id="example" onLoad="displayResult()">
</body>
</html>

When I run show_xsl.asp , it shows an error..This is an error:
"The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML document."

Reply With Quote
  #2 (permalink)  
Old June 11th, 2008, 02:05 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Your transform is not well-formed, it uses xsl:transform as the opening tag and xsl:stylesheet as the closing tag. You can use either form but they must match. Although xsl:transform is arguably the more logically named of the two you will find that most people and examples use xsl:stylesheet.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old June 11th, 2008, 03:50 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>Your transform is not well-formed

Well spotted, Joe, I was struggling with that one!

I would strongly recommend developing XSLT stylesheets in a free-standing environment (for example, Stylus Studio, XML Spy, oXygen, or Kernow with Saxon) before you deploy them in a web server or web browser. You will find the diagnostics much more helpful.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Reply With Quote
  #4 (permalink)  
Old June 12th, 2008, 07:24 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by mhkay
 >Your transform is not well-formed

Well spotted, Joe, I was struggling with that one!

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
Another item to cross off my things-to-do-before-you-die list, I answered an XSLT query that Michael Kay struggled with :)

--

Joe (Microsoft MVP - XML)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show CURRENT DATE when transforming XML using XSLT richieWolf XSLT 0 October 20th, 2007 07:47 PM
xslt slide show kawlaelo XSLT 6 February 13th, 2007 10:41 AM
Database unable to show result. (ASP.NET C#) richie86 ASP.NET 1.0 and 1.1 Basics 3 November 10th, 2005 01:59 PM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
XSLT for complicated xml to xml transf. required doug@sirvisetti XSLT 3 June 17th, 2005 04:26 PM



All times are GMT -4. The time now is 04:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.