Loading the stylesheet with Java

Discussion in 'XML' started by Michael, Aug 24, 2003.

  1. Michael

    Michael Guest

    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.xerces.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$RewindableInputStream.read(Unknown
    Source)
    at
    org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
    at
    org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown
    Source)
    at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
    at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown 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.java:145)
    at net.sf.saxon.event.Sender.send(Sender.java:50)
    at
    net.sf.saxon.TransformerFactoryImpl.getAssociatedStylesheet(TransformerFactoryImpl.java:171)
    at ch.qXMLsigner.viewer.Viewer.actionPerformed(Viewer.java:289)
    at
    javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
    at
    javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
    at
    javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
    at
    javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
    at javax.swing.AbstractButton.doClick(AbstractButton.java:289)
    at
    javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:1113)
    at
    javax.swing.plaf.basic.BasicMenuItemUI$MouseInputHandler.mouseReleased(BasicMenuItemUI.java:943)
    at java.awt.Component.processMouseEvent(Component.java:5134)
    at java.awt.Component.processEvent(Component.java:4931)
    at java.awt.Container.processEvent(Container.java:1566)
    at java.awt.Component.dispatchEventImpl(Component.java:3639)
    at java.awt.Container.dispatchEventImpl(Container.java:1623)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at
    java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
    at
    java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
    at java.awt.Container.dispatchEventImpl(Container.java:1609)
    at java.awt.Window.dispatchEventImpl(Window.java:1590)
    at java.awt.Component.dispatchEvent(Component.java:3480)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
    at
    java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
    at
    java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
    at
    java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
    at
    java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    If anyone could help me I would be very thanksful.

    Kind Regards
    Michael
    Michael, Aug 24, 2003
    #1
    1. Advertising

  2. Michael

    Michael Guest

    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
    Michael, Aug 24, 2003
    #2
    1. Advertising

  3. Michael

    Michael Guest

    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.
    Michael, Aug 24, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Y2FtcHdlcw==?=
    Replies:
    1
    Views:
    1,721
    =?Utf-8?B?Y2FtcHdlcw==?=
    Oct 29, 2004
  2. =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=

    Stylesheet referanse i stylesheet

    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=, Jul 3, 2004, in forum: XML
    Replies:
    3
    Views:
    562
    =?ISO-8859-1?Q?J=F8rn_Tommy_Kinder=E5s?=
    Jul 4, 2004
  3. Steven An
    Replies:
    1
    Views:
    490
    Martin Honnen
    Nov 23, 2004
  4. David Blickstein
    Replies:
    3
    Views:
    1,025
    David Blickstein
    Aug 2, 2005
  5. David Blickstein
    Replies:
    14
    Views:
    6,305
    Harrie
    Oct 16, 2005
Loading...

Share This Page