By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,919 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,919 IT Pros & Developers. It's quick & easy.

Loading the stylesheet with Java

P: n/a
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 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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 17 '05 #2

P: n/a
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 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.