Skip to main content

How to add xml-stylesheet tag to xml file

5 replies [Last post]
varun_nk
Offline
Joined: 2008-04-17
Points: 0

Hi All

I have an XML file to which I wish to append

<?xml-stylesheet type="text/xsl" href="cactus-report.xsl"?>

to the second line of the xml file.

This is how the XML file looks like now.

<?xml version="1.0" encoding="UTF-8"?>

My XML file should look like this

<?xml version="1.0" encoding="UTF-8"?>
[i]<?xml-stylesheet type="text/xsl" href="cactus-report.xsl"?>

[/i]

Can anyone help me out.

Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
joehw
Offline
Joined: 2004-12-15
Points: 0

To my limited knowledge, both IE and Firefox support XSLT and would transform the xml using the instruction you added. While you're asking how to add xml-stylesheet tag to xml file, you already did :) Did you not see it working?

Joe

varun_nk
Offline
Joined: 2008-04-17
Points: 0

Hi joehw

I am trying to perform in-container testing using cactus. The cactus docs mention that one should place the cactus-report.xsl in the webapp directory (for Tomcat) and paste the following URL type ([b]http://ma-india-dt4129.asia.manh.com:37010/ServletTestRunner?suite=com.logistics.ucl.qa.ClientTest&xsl=cactus-report.xsl[/b]) in the browser which results in a nice XSL styled Unit Test report. But, I use JBOSS 4.1 as my server and place the XSL in the WEB-INF(I hope this is right). Unfortunately I do not see the report but instead I get this output in my window.

[b]The XML page cannot be displayed
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

--------------------------------------------------------------------------------

The stylesheet does not contain a document element. The stylesheet may be empty, or it may not be a well-formed XML documen...[/b]

Therefore I tried an alternative but nonetheless a very bad route towards solving this problem. I would save the XML report after accessing this URL ([b]http://ma-india-dt4129.asia.manh.com:37010/ServletTestRunner?suite=com.logistics.ucl.qa.ClientTest[/b]) and add the [b][/b] manually to the XML file and place the XSL file in the same directory as XML. Now when I try to open the XML file in IE I get that beautiful report that I so long for!!

The method I use is definitely bad. I wish I could get the report working as per CACTUS' docs. I hope you understood my query. Thanks for your reply though :). Any other ideas how to proceed?

Thanks

joehw
Offline
Joined: 2004-12-15
Points: 0

I'm not familiar with JBoss or cactus. But WEB-INF is not the right place to place your stylesheet. WEB-INF contains resources that define a web application.

The error message you got meant that the browser would not find the style sheet. That parameter (xsl=cactus-report.xsl) meant that ServletTestRunner is told to find the xsl file in the root directory of the application. Again I'm not familiar with JBoss or Cactus, but if you've deployed cactus as a war file, try add the stylesheet to its root directory.

Do some experiment, I'm sure you could figure it out :)

Good luck,
Joe

varun_nk
Offline
Joined: 2008-04-17
Points: 0

Thanks Joe

I figured it out. I placed the xsl in the war that JBOSS unpacked..thanks for your help :)

joehw
Offline
Joined: 2004-12-15
Points: 0

You're very welcome. Glad you figured it out :)

Joe