 |
| 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
|
|
|
|

August 18th, 2010, 09:38 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

August 18th, 2010, 09:54 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|

August 18th, 2010, 09:55 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
|
|
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
|
|

August 18th, 2010, 11:07 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

August 18th, 2010, 11:16 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
Yep, that's not a valid XML document.
Firstly it contains no root element.
Secondly the & should be replaced with an &
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 & Play PCI Device Enumeration</FILEDESCRIPTION>
<FILEVERSION>5.00.2195.6655</FILEVERSION>
<PRODUCTNAME>Microsoft(R) Windows (R) 2</PRODUCTNAME>
</PRODUCT>
Last edited by samjudson; August 18th, 2010 at 11:21 AM..
|
|

August 18th, 2010, 01:32 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

August 19th, 2010, 07:23 AM
|
|
Registered User
|
|
Join Date: Aug 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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 &"
This is the problem - the xml I am getting does not have the ampersand replaced by an "&" - I'm wondering if there is a way to do this on the fly in my xsl stylesheet -
|
|

August 19th, 2010, 07:26 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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.
|
|
 |