Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 18th, 2010, 09:38 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default viewing xml in browser - writing xsl stylesheet

I am writing a quick xsl stylesheet to view data being returned from an internal tool. The data contains ampersands "&".... When I try to view the data in a browser I receive the "whitespace is not allowed" error, but from what I have read, the transform is really failing on the '&" earlier in the text. This is how I am displaying the data:

Code:
<td><xsl:value-of select="COMPANY"></td>
I have tried the disable-output-escaping="yes" as follows:
Code:
<td><xsl:value-of disable-output-escaping="yes" select="COMPANY"></td>
and have tried the ENTITY value, but nothing seems to work. All I want to do is view the data in a browser...

Can anyone tell me what I am doing wrong?
 
Old August 18th, 2010, 09:54 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

If the 'data' contains an unescaped ampersand then it not valid XML, so no amount of fiddling on your part will fix this with XSLT.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old August 18th, 2010, 09:55 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

How about showing us the data that causes that error? Are those ampersands properly escaped? Is "whitespace is not allowed" really the complete error message? And which tool gives you that error? Running stylesheets in the browser is not a good way to debug problems, if you run them first with a stand-alone processor like Saxon you get much better error reporting. Currently we don't know whether the error occurs with parsing the input or with parsing the XML stylesheet or with the output created.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old August 18th, 2010, 11:07 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default viewing xml in browser - writing xsl stylesheet

Obviously I am a newbie at xml and xls - I was handed some xml code by a client and asked to write a stylesheet so they could quickly view their data in a browser. Here is part of the xml that is generated by their program:

Code:
<NAME>PCI</NAME>
<DESCRIPTION>PCI-Bus-Atlantol</DESCRIPTION>
<DISPLAYNAME>PCI-Bus-Atlantol</DISPLAYNAME>
<COMPANY>Microsoft Corporation</COMPANY>
<FILEDESCRIPTION>Plug & Play PCI Device Enumeration</FILEDESCRIPTION>
<FILEVERSION>5.00.2195.6655</FILEVERSION>
<PRODUCTNAME>Microsoft(R) Windows (R) 2<PRODUCTNAME>
I can ask them to revamp their xml, but that will take some time. In the meantime, is there a way around the "&" issue?
 
Old August 18th, 2010, 11:16 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Yep, that's not a valid XML document.

Firstly it contains no root element.

Secondly the & should be replaced with an &amp;

Thirdly the PRODUCTNAME element is not closed properly.

Code:
<PRODUCT>
  <NAME>PCI</NAME>
  <DESCRIPTION>PCI-Bus-Atlantol</DESCRIPTION>
  <DISPLAYNAME>PCI-Bus-Atlantol</DISPLAYNAME>
  <COMPANY>Microsoft Corporation</COMPANY>
  <FILEDESCRIPTION>Plug &amp; Play PCI Device Enumeration</FILEDESCRIPTION>
  <FILEVERSION>5.00.2195.6655</FILEVERSION>
  <PRODUCTNAME>Microsoft(R) Windows (R) 2</PRODUCTNAME>
</PRODUCT>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?

Last edited by samjudson; August 18th, 2010 at 11:21 AM..
 
Old August 18th, 2010, 01:32 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your question was about viewing XML in a browser. But it seems you actually want to view something that isn't XML. There are ways of doing that, but you can't do it with XSLT.

There are a couple of utilities - TagSoup and JTidy - that were designed to turn undisciplined HTML into structured, well-formed XML. I've heard it said that they do a good job repairing broken XML as well. But it's far better to ensure that the XML isn't broken in the first place.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old August 19th, 2010, 07:23 AM
Registered User
 
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default viewing xml in browser

Sorry, guess I wasn't clear... the code bit above is only a part of the xml. There is a root element, I just did not show it above. The crux of my problem is this:

"Secondly the & should be replaced with an &amp;"

This is the problem - the xml I am getting does not have the ampersand replaced by an "&amp" - I'm wondering if there is a way to do this on the fly in my xsl stylesheet -
 
Old August 19th, 2010, 07:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

No, there is no way to do this in XSLT, simply because what you are receiving ISN'T XML, therefore cannot be processed using XSLT without some form of pre-processing.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Theme Error When Viewing in Browser chrisreyno BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 3 September 11th, 2009 10:44 AM
Browser transform using local XSL and remote XML sosarder XSLT 1 March 13th, 2007 02:58 PM
Viewing code rather than content in browser aspnewbie Classic ASP Basics 2 March 27th, 2006 10:47 AM
scx to html, using a xsl stylesheet bluetorch XSLT 0 October 18th, 2005 11:38 AM
XSL Stylesheet Problem Ben Horne XSLT 4 March 6th, 2004 05:50 AM





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