[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to get the node list?

Subject: How to get the node list?
From: Cheun N Chong <cnc99r@xxxxxxxxxxxxxxx>
Date: Wed, 19 Apr 2000 14:24:37 +0100 (BST)
import org.apache.xerces.parsers.domparser outputf
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.

PrintTreeStructure.java 
=======================
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;

    System.out.println(length);
  }
}

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>

foo.xml
=======
<?xml version="1.0"?>
<doc>Hello</doc>

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


	Thousand thanks!


Best regards,
Cheun Ngen CHONG



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.