473,221 Members | 1,935 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,221 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 17 '05 #1
2 4172
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
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 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: 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...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.