《XML一朝一夕》第二篇

/**
*@author zwm XSLExample
*/
package myxml.xml;

import oracle.xml.parser.v2.DOMParser;
import oracle.xml.parser.v2.XMLDocument;
import java.io.FileInputStream;
import oracle.xml.parser.v2.XSLStylesheet;
import oracle.xml.parser.v2.XSLProcessor;
import oracle.xml.parser.v2.XMLDocumentFragment;

public class XSLExample {
    public XSLExample() {
    }
    public static void main(String[] args) {
        try{
        DOMParser parser;
        XMLDocument xmldoc,xsldoc,out;
        FileInputStream xmlstream,xslstream;
        //create an instance of the DOMParser
        parser=new DOMParser();
        parser.setPreserveWhitespace(true);
        //parse input XML file
        xmlstream=new FileInputStream("one.xml");
        parser.parse(xmlstream);
        xmldoc=parser.getDocument();
        //parse input XSL file
        xslstream=new FileInputStream("two.xsl");
        parser.parse(xslstream);
        xsldoc=parser.getDocument();
        //instantiate a stylesheet
        XSLProcessor processor=new XSLProcessor();
        XSLStylesheet xsl=processor.newXSLStylesheet(xsldoc);
        XMLDocumentFragment result=processor.processXSL(xsl,xmldoc);
        //print the transformed document
        result.print(System.out);
        }catch(Exception e){
            e.printStackTrace();
        }

    }
}



one.xml***************************

<?xml version="1.0" encoding="gb2312"?>
<booklist>
  <book isbn="abbddf">
  <title>oracle and xml</title>
  <author>zwm</author>
  </book>
  <book isbn="dddd">
<title>zhonggo</title>
<author>cuba</author>
  </book>
</booklist>

two.xsl**************************************
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:template match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
  <xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"></xsl:apply-templates>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

你可能感兴趣的:(oracle,xml,XSL)