[jdom-interest] Help XSLT/Piped Streams?

markus_tripp at sonynetservices.com markus_tripp at sonynetservices.com
Tue Nov 14 07:27:23 PST 2000



Hello,

for test purposes it is often useful to process a XSLT transformations
directly from a JDOM document using a XSL stylesheet. I know that a direct
integration of XSLT into JDOM would be much better - and I think Bob is
working on this - but sometimes a version which pipes the output to an
external XSLT processor like Xalan would help for the moment. I wrote such
a simple class which uses Apache Xalan 2 (http://xml.apache.org). I have
attached the source file "JDOMSimpleXSLTProcessor.java" to this email.
Within my project I placed the file into the package
"org.jdom.contrib.xslt" because did not find a better place for now.
Because I am behind a firewall I cannot place it directly to the CVS.


Requirements:
=============

xalan.jar and xerces.jar in the classpath (make sure to have the latest
Xalan 2 version in the classpath).


Sample Code of using JDOMSimpleXSLTProcessor
(TestJDOMSimpleXSLProcessor.java):
===============================================================================

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.contrib.xslt.JDOMSimpleXSLTProcessor;
import org.xml.sax.InputSource;
import org.apache.trax.Result;

public class TestJDOMSimpleXSLTProcessor {
  public static void main(String[] args) {
    Document document;
    Element element;
    InputSource xsl = new InputSource("foo.xsl");
    Result out = new Result(System.out);

    element = new Element("doc");
    element.setText("Hello");
    document = new Document(element);

    try {
      JDOMSimpleXSLTProcessor.process(document, xsl, out);
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


XSL file (foo.xsl):
===================

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="doc">
    <out><xsl:value-of select="."/></out>
  </xsl:template>
</xsl:stylesheet>


Markus Tripp

(See attached file: JDOMSimpleXSLTProcessor.java)





Nick Vincent <Nick at neoworks.com>@jdom.org on 13.11.2000 18:35:32

Gesendet von:  jdom-interest-admin at jdom.org


An:   "'jdom-interest at jdom.org'" <jdom-interest at jdom.org>
Kopie:
Thema:    [jdom-interest] Help XSLT/Piped Streams?


Hi,

I'm using JDOM at the moment, and am trying to pipe an output stream into
Xalan, as per the instructions in the JDOM FAQ.  I have tried to get this
working a lot of ways, but when I attempt to pipe the input the XSLT parser
hangs, as if it is still waiting for input from the input stream.

The same code works if replace the input stream with othewr stream types
(i.e. strings, files), and I have tried flushing the streams everywhere I
can to no avail.  Is there any sample code of this working (I have checked
out CVS today to see if this example has been added, but could not find
it)?

Many thanks,


Nick Vincent
NeoWorks
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



-------------- next part --------------
A non-text attachment was scrubbed...
Name: JDOMSimpleXSLTProcessor.java
Type: application/octet-stream
Size: 4832 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20001114/218ea460/JDOMSimpleXSLTProcessor.obj


More information about the jdom-interest mailing list