Woops -- where did that bogus address come from? Let me try again: _____
From: siegfried [mailto:[EMAIL PROTECTED] Sent: Thursday, September 04, 2008 6:56 PM To: '[EMAIL PROTECTED]'; 'David Bertoni' Cc: '[EMAIL PROTECTED]' Subject: RE: FW: command line tool for reading and writing to/from stdin and stdout? Sure! This program from c:/dev/xalan/xalan-j_2_7_1/samples/UseStylesheetPI/UseStylesheetPI.java (see attachment) does not work because I made a minor modification to read from standard input on line 58. Can you help me make it work? Here is the fragment redundantly for your reding pleasure. Note that if I hard code a file name on line 58, line 62 works. Thanks! Siegfried TransformerFactory tFactory = TransformerFactory.newInstance(); Source stylesheet = tFactory.getAssociatedStylesheet (new StreamSource(System.in),media, title, charset); Transformer transformer = tFactory.newTransformer(stylesheet); /* 60*/ transformer.transform(new StreamSource(System.in), new StreamResult(new java.io.FileOutputStream(java.io.FileDescriptor.out))); _____ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Thursday, September 04, 2008 5:03 PM To: David Bertoni Cc: siegfried; [EMAIL PROTECTED] Subject: Re: FW: command line tool for reading and writing to/from stdin and stdout? > I'm not sure what you mean by "having standard input open twice." Are > you saying you want to read both the input document and the stylesheet > from system.in? That isn't possible, since there would be no way to > demarcate each entity in the stream. Well, it's possible -- but you'd need to develop your own data stream protocol which allowed you to express logical end-of-file, and do some entity-resolver work to read twice from this delimited stream using different URIs. Or, simpler but less efficient, have a preprocessing stage which reads that delimited stream, writes the documents into scratch files, and then process from those. But I agree that we're guessing at the intended meaning. Siegfried, maybe you ought to take a long step back and explain exactly what it is you're trying to do. If you want to read both the stylesheet and document from stdin, you need a delimiting and resolver solution as discussed above. If you just want to read the document from stdin, and the stylesheet from a file, while writing to stdout... well, that should be a trivial change to one of the Xalan sample programs. If you're trying to do something else, you'll need to explain what in enough detail that we can advise you. The mind-reading support service costs real money. <smile/>
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /* * $Id: UseStylesheetPI.java,v 1.1 2008/09/04 19:32:00 Administrator Exp Administrator $ * $Log: UseStylesheetPI.java,v $ * Revision 1.1 2008/09/04 19:32:00 Administrator * Initial revision * * Begin commands to execute this file using Java with bash * export CLASSPATH=bin\;.\;C\:\\dev\\xalan\\xalan-j_2_7_1\\build\\classes\;C\:\\dev\\xalan\\xalan-j_2_7_1\\*\;C\:\\dev\\bsf\\bsf-2.4.0\\lib\\*\;c\:\\dev\\apache\\common\\commons-logging-1.1.1\\*\;C\:\\dev\\mozilla\\rhino1_7R1\\*\;C\:\\dev\\ant\\apache-ant-1.6.5\\lib\\* * javac *.java * java UseStylesheetPI <<EOF * <?xml version="1.0"?> * <?xml-stylesheet type="text/xsl" href="foo.xsl"?> * <doc> * Hello * </doc> * EOF * rm *.class * End commands to execute this file using Java with bash */ import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; public class UseStylesheetPI { public static void main(String[] args) throws TransformerException, TransformerConfigurationException { String media= null , title = null, charset = null; try { TransformerFactory tFactory = TransformerFactory.newInstance(); Source stylesheet = tFactory.getAssociatedStylesheet (new StreamSource(System.in),media, title, charset); Transformer transformer = tFactory.newTransformer(stylesheet); transformer.transform(new StreamSource(System.in), new StreamResult(new java.io.FileOutputStream(java.io.FileDescriptor.out))); System.out.println("************* The result is in foo.out *************"); } catch (Exception e) { e.printStackTrace(); } } }