xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cheun N Chong <cnc...@ecs.soton.ac.uk>
Subject Re: How to get the node list?
Date Wed, 19 Apr 2000 14:08:38 GMT

Hi, all it is me again
I know how to print the length of the node list
Sorry for asking the wrong question

Is it possible to print out String "Hello"?

Thousand thanks
and terribly sorry

Dear all, 

	Sorry to bother. I need help. I have attach my codes as the
following: PrintTreeStructure.java, foo.xml, foo.xsl and the output,
tree.xml. I want to make the PrintTreeStructure to print out the nodes of
the output of the parser, but the node list length is 0. I am not sure the
way I am doing it is correct. I need your expertise indeed. Btw, I am
using XML4J and LotusXSL.

import java.io.*;
import java.net.MalformedURLException;

import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.XSLTResultTarget;
import org.apache.xalan.xslt.XSLTProcessorFactory;

import org.apache.xalan.xpath.xml.TreeWalker;
import org.apache.xalan.xpath.xml.FormatterToXML;
import org.apache.xerces.dom.DocumentImpl;
import org.apache.xerces.dom.NodeImpl;
import org.apache.xerces.parsers.DOMParser;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

public class PrintTreeStructure {

  public static void main(String[] args) throws Exception, Throwable {

    // Create the output file called tree.xml
    FileOutputStream fileOutput = new FileOutputStream(new File("tree.xml"));

    // Create an XSLT processor
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();

    // Create input source documents
    XSLTInputSource xmlID = new XSLTInputSource("foo.xml");
    XSLTInputSource xslID = new XSLTInputSource("foo.xsl");

    // Create a DOM Document node to attach the result nodes to
    Document out = new DocumentImpl();
    XSLTResultTarget result = new XSLTResultTarget(out);

    // Process the source tree and produce the result tree
    processor.process(xmlID, xslID, result);

    // Get the node list from the document
    NodeList nodelist = out.getChildNodes();

    // Length of the node list
    int length = (nodelist != null) ? nodelist.getLength() : 0;


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

<?xml version="1.0"?>

tree.xml (the output)
<?xml version="1.0" encoding="UTF-8"?>

	Thousand thanks!

Best regards,
Cheun Ngen CHONG

View raw message