473,385 Members | 1,610 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Loading the stylesheet with Java

Hello

I am trying to write a Java-Program which converts a XML-file in a HTML.
It should take the Transformation-file from the XML-file itself.

Below find a possible XML-file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 3 U (http://www.xmlspy.com) by Michael
Herren (private) -->
<?xml-stylesheet type="text/xsl" href="ch/qXMLsigner/files/order.xslt"
type="text/xsl?>
<order xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="ch/qXMLsigner/files/order.xsd">
<address>
<name>Herren</name>
<firstname>Michael</firstname>
<street>Postgasse 62</street>
<zip>3011</zip>
<place>Bern</place>
</address>
<item>
<quantity>2</quantity>
<productcode>684562</productcode>
<description>DVD "Cruel Intentions"</description>
<unitprice>25</unitprice>
<price>50</price>
</item>
<conditions>
<discount>
<percent>5</percent>
<amount>3.9</amount>
</discount>
<fees>10</fees>
<currency>CHF</currency>
</conditions>
<totalamount>84.1</totalamount>
</order>

When I try to load the stylesheet a Java-Exception is thrown. Below find
the Java code:

XMLReader reader =
XMLReaderFactory.createXMLReader("org.apache.xerce s.parsers.SAXParser");
InputSource inputSource = new InputSource(new
FileInputStream("ch/qXMLsigner/files/order.xml"));
reader.parse(inputSource);
SAXSource xmlDocument = new SAXSource(reader, inputSource);
transformXMLItem.setEnabled(true);
TransformerFactoryImpl transFactory = new TransformerFactoryImpl();
Source xsltSource = transFactory.getAssociatedStylesheet(xmlDocument,
null, null, null);

And the exception looks like:

Failed while looking for xml-stylesheet PI
java.io.IOException: The system cannot find the path specified
java.io.IOException: The system cannot find the path specified
at java.io.FileInputStream.read(Native Method)
at
org.apache.xerces.impl.XMLEntityManager$Rewindable InputStream.read(Unknown
Source)
at
org.apache.xerces.impl.XMLEntityManager.setupCurre ntEntity(Unknown Source)
at
org.apache.xerces.impl.XMLVersionDetector.determin eDocVersion(Unknown
Source)
at org.apache.xerces.parsers.XML11Configuration.parse (Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(U nknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse( Unknown Source)
at net.sf.saxon.event.Sender.sendSAXSource(Sender.jav a:145)
at net.sf.saxon.event.Sender.send(Sender.java:50)
at
net.sf.saxon.TransformerFactoryImpl.getAssociatedS tylesheet(TransformerFactoryImpl.java:171)
at ch.qXMLsigner.viewer.Viewer.actionPerformed(Viewer .java:289)
at
javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1764)
at
javax.swing.AbstractButton$ForwardActionEvents.act ionPerformed(AbstractButton.java:1817)
at
javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:419)
at
javax.swing.DefaultButtonModel.setPressed(DefaultB uttonModel.java:257)
at javax.swing.AbstractButton.doClick(AbstractButton. java:289)
at
javax.swing.plaf.basic.BasicMenuItemUI.doClick(Bas icMenuItemUI.java:1113)
at
javax.swing.plaf.basic.BasicMenuItemUI$MouseInputH andler.mouseReleased(BasicMenuItemUI.java:943)
at java.awt.Component.processMouseEvent(Component.jav a:5134)
at java.awt.Component.processEvent(Component.java:493 1)
at java.awt.Container.processEvent(Container.java:156 6)
at java.awt.Component.dispatchEventImpl(Component.jav a:3639)
at java.awt.Container.dispatchEventImpl(Container.jav a:1623)
at java.awt.Component.dispatchEvent(Component.java:34 80)
at
java.awt.LightweightDispatcher.retargetMouseEvent( Container.java:3450)
at
java.awt.LightweightDispatcher.processMouseEvent(C ontainer.java:3165)
at java.awt.LightweightDispatcher.dispatchEvent(Conta iner.java:3095)
at java.awt.Container.dispatchEventImpl(Container.jav a:1609)
at java.awt.Window.dispatchEventImpl(Window.java:1590 )
at java.awt.Component.dispatchEvent(Component.java:34 80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java: 450)
at
java.awt.EventDispatchThread.pumpOneEventForHierar chy(EventDispatchThread.java:197)
at
java.awt.EventDispatchThread.pumpEventsForHierarch y(EventDispatchThread.java:150)
at
java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:144)
at
java.awt.EventDispatchThread.pumpEvents(EventDispa tchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThre ad.java:99)

If anyone could help me I would be very thanksful.

Kind Regards
Michael

Jul 20 '05 #1
2 3322
John Bokma wrote:
Michael wrote:
Hello

I am trying to write a Java-Program which converts a XML-file in a
HTML. It should take the Transformation-file from the XML-file itself.

Below find a possible XML-file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 3 U (http://www.xmlspy.com) by Michael
Herren (private) -->
<?xml-stylesheet type="text/xsl" href="ch/qXMLsigner/files/order.xslt"
type="text/xsl?>

^ missing "

has the directory which contains this file a dir ch?

John


John,

Yes. As you can see in the code, the corresponding XML-schema is in the
same directory. And I'm able to validate the XML-file.

I also removed the second type="text/xsl" attribute. But it still does
not work.

Thank you for your help

Jul 20 '05 #2
John Bokma wrote:
Michael wrote:
Hello

I am trying to write a Java-Program which converts a XML-file in a
HTML. It should take the Transformation-file from the XML-file itself.

Below find a possible XML-file:

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 rel. 3 U (http://www.xmlspy.com) by Michael
Herren (private) -->
<?xml-stylesheet type="text/xsl" href="ch/qXMLsigner/files/order.xslt"
type="text/xsl?>

^ missing "

has the directory which contains this file a dir ch?

John

When I use the following code, everything works fine:

Source xmlSource = new StreamSource("ch/qXMLsigner/files/order.xml");
Source xsltSource = new StreamSource("ch/qXMLsigner/files/order.xslt");
TransformerFactory transFactory = TransformerFactory.newInstance();
Transformer transformer = transFactory.newTransformer(xsltSource);
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
transformer.transform(xmlSource, new StreamResult(oStream));

And the path is the same.

Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Michael | last post by:
Hello I am trying to write a Java-Program which converts a XML-file in a HTML. It should take the Transformation-file from the XML-file itself. Below find a possible XML-file: <?xml...
3
by: Sarah Haskins | last post by:
I have a few questions about this problem I'm having involving XML, DTD, and XSL. I'm working with this DTD which defines a stylesheet, as such... <?xml version="1.0" encoding="UTF-8"?>...
0
by: Martin Dugeorge | last post by:
Hello all, i've got an XSLT stylesheet containing a XSLT document function with an absolute URI : <xsl:for-each select="document('http://x.y.z/dir/a.xml')/root/element">...</xsl:for-each> ...
1
by: campwes | last post by:
Hey, all! We're having trouble displaying SQL Server data in a web site as XML, using a transform. The query is a simple SELECT statement. When running the query, we get the following error from...
3
by: fbwhite | last post by:
I am having an issue (maybe two issues) in my application regarding a stylesheet not loading and I am getting Javascript Errors. If I clean out a client's temporary internet files and then browse...
1
by: msarora | last post by:
I'm using SimpleTransform.java (renamed as ReceiptTransformer.java for custom use) found in xalan-j_2_7_0 samples directory for transformations in my custom application. The program compiles...
1
by: SagarDoke | last post by:
Hello, this is my servlet: String skill_id = request.getParameter("skill_id"); request.setAttribute("Skill_id", skill_id); RequestDispatcher rd = ...
8
by: Mark Shroyer | last post by:
I just completed a new design for a personal web site. After finishing the basic CSS stuff and double-checking it in Safari, FF, Opera, et al., I put on my war paint and fired up IE7 to figure out...
3
by: Leighya | last post by:
Im currently working on this xml file but when i load it to Mozilla, i got an error "Error Loading Stylesheet: Xpath parse failure: invalid variable name" It loads on IE properly. Only with the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.