dleslie     00/12/05 05:33:28

  Added:       java/samples/DOM2DOM birds.xml birds.xsl DOM2DOM.java
                        readme.html
  Log:
  Revised and renamed this sample: transforms from DOMSource
  to DOMResult.
  
  Revision  Changes    Path
  1.1                  xml-xalan/java/samples/DOM2DOM/birds.xml
  
  Index: birds.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <Class>
  <Order Name="TINAMIFORMES">
          <Family Name="TINAMIDAE">
              <Species Scientific_Name="Tinamus major">  Great 
Tinamou.</Species>
              <Species Scientific_Name="Nothocercus">Highland Tinamou.</Species>
              <Species Scientific_Name="Crypturellus soui">Little 
Tinamou.</Species>
              <Species Scientific_Name="Crypturellus cinnamomeus">Thicket 
Tinamou.</Species>
              <Species Scientific_Name="Crypturellus boucardi">Slaty-breasted 
Tinamou.</Species>
              <Species Scientific_Name="Crypturellus kerriae">Choco 
Tinamou.</Species>
          </Family>
      </Order>
  <Order Name="GAVIIFORMES">
          <Family Name="GAVIIDAE">
              <Species Scientific_Name="Gavia stellata">Red-throated 
Loon.</Species>
              <Species Scientific_Name="Gavia arctica">Arctic Loon.</Species>
              <Species Scientific_Name="Gavia pacifica">Pacific Loon.</Species>
              <Species Scientific_Name="Gavia immer">Common Loon.</Species>
              <Species Scientific_Name="Gavia adamsii">Yellow-billed 
Loon.</Species>
          </Family>
      </Order>
  
  
  <Order Name="PODICIPEDIFORMES">
          <Family Name="PODICIPEDIDAE">
              <Species Scientific_Name="Tachybaptus dominicus">Least 
Grebe.</Species>
              <Species Scientific_Name="Podilymbus podiceps">Pied-billed 
Grebe.</Species>
              <Species Scientific_Name="">Atitlan Grebe.</Species>
              <Species Scientific_Name="">Horned Grebe.</Species>
              <Species Scientific_Name="">Red-necked Grebe.</Species>
              <Species Scientific_Name="">Eared Grebe.</Species>
              <Species Scientific_Name="">Western Grebe.</Species>
              <Species Scientific_Name="">Clark's Grebe.</Species>
              <Species Scientific_Name=""/>
          </Family>
      </Order>
  
  
  <Order Name="PROCELLARIIFORMES">
          <Family Name="DIOMEDEIDAE">
              <Species Scientific_Name="Thalassarche 
chlororhynchos">Yellow-nosed Albatross. (A)</Species>
              <Species Scientific_Name="Thalassarche cauta">Shy Albatross. 
(A)</Species>
              <Species Scientific_Name="Thalassarche melanophris">Black-browed 
Albatross. (A)</Species>
              <Species Scientific_Name="Phoebetria palpebrata">Light-mantled 
Albatross. (A)</Species>
              <Species Scientific_Name="Diomedea exulans">Wandering Albatross. 
(A)</Species>
              <Species Scientific_Name="Phoebastria immutabilis">Laysan 
Albatross.</Species>
              <Species Scientific_Name="Phoebastria nigripes">Black-footed 
Albatross.</Species>
              <Species Scientific_Name="Phoebastria albatrus">Short-tailed 
Albatross. (N)</Species>
          </Family>
          <Family Name="PROCELLARIIDAE">
              <Species Scientific_Name="Fulmarus glacialis">Northern 
Fulmar.</Species>
              <Species Scientific_Name="Pterodroma neglecta">Kermadec Petrel. 
(A)</Species>
              <Species Scientific_Name="Pterodroma arminjoniana">Herald Petrel. 
(A)</Species>
              <Species Scientific_Name="Pterodroma ultima">Murphy's Petrel. 
(N)</Species>
              <Species Scientific_Name="Pterodroma inexpectata">Mottled Petrel. 
(A)</Species>
              <Species Scientific_Name="Pterodroma cahow">Bermuda 
Petrel.</Species>
              <Species Scientific_Name="Pterodroma hasitata">Black-capped 
Petrel.</Species>
              <Species Scientific_Name="Pterodroma externa">Juan Fernandez 
Petrel. (N)</Species>
              <Species Scientific_Name="Pterodroma phaeopygia">Dark-rumped 
Petrel.</Species>
              <Species Scientific_Name="Pterodroma cervicalis">White-necked 
Petrel. (H)</Species>
              <Species Scientific_Name="Pterodroma hypoleuca">Bonin Petrel. 
(H)</Species>
              <Species Scientific_Name="Pterodroma nigripennis">Black-winged 
Petrel. (H, A)</Species>
              <Species Scientific_Name="Pterodroma cookii">Cook's Petrel. 
(N)</Species>
              <Species Scientific_Name="Pterodroma longirostris">Stejneger's 
Petrel. (A)</Species>
              <Species Scientific_Name="Bulweria bulwerii">Bulwer's Petrel. 
(H)</Species>
              <Species Scientific_Name="Bulweria fallax">Jouanin's Petrel. (H, 
A)</Species>
              <Species Scientific_Name="Procellaria parkinsoni">Parkinson's 
Petrel. (N)</Species>
              <Species Scientific_Name="Calonectris leucomelas">Streaked 
Shearwater. (A)</Species>
              <Species Scientific_Name="Calonectris diomedea">Cory's 
Shearwater. (N)</Species>
              <Species Scientific_Name="Puffinus creatopus">Pink-footed 
Shearwater. (N)</Species>
              <Species Scientific_Name="Puffinus carneipes">Flesh-footed 
Shearwater. (N)</Species>
              <Species Scientific_Name="Puffinus gravis">Greater Shearwater. 
(N)</Species>
              <Species Scientific_Name="Puffinus pacificus">Wedge-tailed 
Shearwater.</Species>
              <Species Scientific_Name="Puffinus bulleri">Buller's Shearwater. 
(N)</Species>
              <Species Scientific_Name="Puffinus griseus">Sooty Shearwater. 
(N)</Species>
              <Species Scientific_Name="Puffinus tenuirostris">Short-tailed 
Shearwater. (N)</Species>
              <Species Scientific_Name="Puffinus nativitatis">Christmas 
Shearwater. (H)</Species>
              <Species Scientific_Name="Puffinus puffinus">Manx 
Shearwater.</Species>
              <Species Scientific_Name="Puffinus auricularis">Townsend's 
Shearwater.</Species>
              <Species Scientific_Name="Puffinus opisthomelas">Black-vented 
Shearwater.</Species>
              <Species Scientific_Name="Puffinus lherminieri">Audubon's 
Shearwater.</Species>
              <Species Scientific_Name="Puffinus assimilis">Little Shearwater. 
(A)</Species>
          </Family>
          <Family Name="HYDROBATIDAE">
              <Species Scientific_Name="Oceanites oceanicus">Wilson's 
Storm-Petrel. (N)</Species>
              <Species Scientific_Name="Pelagodroma marina">White-faced 
Storm-Petrel. (A)</Species>
              <Species Scientific_Name="Hydrobates pelagicus">European 
Storm-Petrel. (A)</Species>
              <Species Scientific_Name="Oceanodroma furcata">Fork-tailed 
Storm-Petrel.</Species>
              <Species Scientific_Name="Oceanodroma leucorhoa">Leach's 
Storm-Petrel.</Species>
              <Species Scientific_Name="Oceanodroma homochroa">Ashy 
Storm-Petrel.</Species>
              <Species Scientific_Name="Oceanodroma castro">Band-rumped 
Storm-Petrel. (N)</Species>
              <Species Scientific_Name="Oceanodroma tethys">Wedge-rumped 
Storm-Petrel. (N)</Species>
              <Species Scientific_Name="Oceanodroma melania">Black 
Storm-Petrel.</Species>
              <Species Scientific_Name="Oceanodroma macrodactyla">Guadalupe 
Storm-Petrel.</Species>
              <Species Scientific_Name="Oceanodroma markhami">Markham's 
Storm-Petrel. (A)</Species>
              <Species Scientific_Name="Oceanodroma tristrami">Tristram's 
Storm-Petrel. (H)</Species>
              <Species Scientific_Name="Oceanodroma microsoma">Least 
Storm-Petrel.</Species>
          </Family>
      </Order>
  
  <Order Name="PELECANIFORMES">
          <Family Name="PHAETHONTIDAE">
              <Species Scientific_Name="Phaethon lepturus">White-tailed 
Tropicbird.</Species>
              <Species Scientific_Name="Phaethon aethereus">Red-billed 
Tropicbird.</Species>
              <Species Scientific_Name="Phaethon rubricauda">Red-tailed 
Tropicbird.</Species>
          </Family>
          <Family Name="SULIDAE">
              <Species Scientific_Name="Sula dactylatra">Masked Booby.</Species>
              <Species Scientific_Name="Sula nebouxii">Blue-footed 
Booby.</Species>
              <Species Scientific_Name="Sula variegata">Peruvian Booby. 
(A)</Species>
              <Species Scientific_Name="Sula leucogaster">Brown Booby.</Species>
              <Species Scientific_Name="Sula sula">Red-footed Booby.</Species>
              <Species Scientific_Name="Morus bassanus">Northern 
Gannet.</Species>
          </Family>
          <Family Name="PELECANIDAE">
              <Species Scientific_Name="Pelecanus erythrorhynchos">American 
White Pelican.</Species>
              <Species Scientific_Name="Pelecanus occidentalis">Brown 
Pelican.</Species>
          </Family>
          <Family Name="PHALACROCORACIDAE">
              <Species Scientific_Name="Phalacrocorax penicillatus">Brandt's 
Cormorant.</Species>
              <Species Scientific_Name="Phalacrocorax brasilianus">Neotropic 
Cormorant.</Species>
              <Species Scientific_Name="Phalacrocorax auritus">Double-crested 
Cormorant.</Species>
              <Species Scientific_Name="Phalacrocorax carbo">Great 
Cormorant.</Species>
              <Species Scientific_Name="Phalacrocorax urile">Red-faced 
Cormorant.</Species>
              <Species Scientific_Name="Phalacrocorax pelagicus">Pelagic 
Cormorant.</Species>
          </Family>
          <Family Name="ANHINGIDAE">
              <Species Scientific_Name="Anhinga anhinga">Anhinga.</Species>
          </Family>
          <Family Name="FREGATIDAE">
              <Species Scientific_Name="Fregata magnificens">Magnificent 
Frigatebird.</Species>
              <Species Scientific_Name="Fregata minor">Great 
Frigatebird.</Species>
              <Species Scientific_Name="Fregata ariel">Lesser Frigatebird. 
(A)</Species>
          </Family>
      </Order>
  </Class>
  
  
  
  1.1                  xml-xalan/java/samples/DOM2DOM/birds.xsl
  
  Index: birds.xsl
  ===================================================================
  <?xml version="1.0"?> 
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; 
version="1.0">
    <xsl:output method="xml" indent="yes"/>
  
  <xsl:template match="Class">
  <BirdInfo>
        <xsl:apply-templates select="Order"/>
  </BirdInfo>
  </xsl:template>
  
  <xsl:template match="Order">
  Order is:  <xsl:value-of select="@Name"/>
        <xsl:apply-templates select="Family"/><xsl:text>
  </xsl:text>
  </xsl:template>
  
  <xsl:template match="Family">
        Family is:  <xsl:value-of select="@Name"/>
        <xsl:apply-templates select="Species | SubFamily | text()"/>
  </xsl:template>
  
  <xsl:template match="SubFamily">
                SubFamily is <xsl:value-of select="@Name"/>
      <xsl:apply-templates select="Species | text()"/>
  </xsl:template>
  
  <xsl:template match="Species">
        <xsl:choose>
          <xsl:when test="name(..)='SubFamily'">
                <xsl:text>      </xsl:text><xsl:value-of select="."/><xsl:text> 
</xsl:text><xsl:value-of select="@Scientific_Name"/>
          </xsl:when>
          <xsl:otherwise>
                <xsl:value-of select="."/><xsl:text> </xsl:text><xsl:value-of 
select="@Scientific_Name"/>
          </xsl:otherwise>
        </xsl:choose>
  </xsl:template>
  
  </xsl:stylesheet>
  
  
  
  1.1                  xml-xalan/java/samples/DOM2DOM/DOM2DOM.java
  
  Index: DOM2DOM.java
  ===================================================================
  /*
   * The Apache Software License, Version 1.1
   *
   *
   * Copyright (c) 1999 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Xalan" and "Apache Software Foundation" must
   *    not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation and was
   * originally based on software copyright (c) 1999, Lotus
   * Development Corporation., http://www.lotus.com.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  // Imported TraX classes
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.stream.StreamSource;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.TransformerException;
  import javax.xml.transform.TransformerConfigurationException;
  import javax.xml.transform.dom.DOMSource;
  import javax.xml.transform.dom.DOMResult;
  
  // Imported java.io classes
  import java.io.IOException;
  import java.io.FileNotFoundException;
  
  // Imported SAX classes
  import org.xml.sax.InputSource;
  import org.xml.sax.SAXException;
  
  // Imported DOM classes
  import org.w3c.dom.Document;
  import org.w3c.dom.Node;
  
  // Imported Serializer classes
  import org.apache.xalan.serialize.OutputFormat;
  import org.apache.xalan.serialize.Serializer;
  import org.apache.xalan.serialize.SerializerFactory;
  
  // Imported JAVA API for XML Parsing classes
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.parsers.ParserConfigurationException; 
  
    /**
     * Show how to transform a DOM tree into another DOM tree.  
     * This uses the javax.xml.parsers to parse an XML file into a 
     * DOM, and create an output DOM.
     */
  public class DOM2DOM
  {
        public static void main(String[] args)
      throws TransformerException, TransformerConfigurationException, 
FileNotFoundException,
             ParserConfigurationException, SAXException, IOException
    {    
          TransformerFactory tFactory = TransformerFactory.newInstance();
  
      if(tFactory.getFeature(DOMSource.FEATURE) && 
tFactory.getFeature(DOMResult.FEATURE))
      {
        // Process the stylesheet StreamSource and generate a Transformer.
        Transformer transformer = tFactory.newTransformer(new 
StreamSource("birds.xsl"));
        
        //Instantiate a DocumentBuilderFactory.
        DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
        
        //Use the DocumentBuilderFactory to create a DocumentBuilder.
        DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
        
        //Use the DocumentBuilder to parse the XML input.
        Document doc = dBuilder.parse("birds.xml");
        
        // Create an empty DOMResult for the Result.
        DOMResult domResult = new DOMResult();
    
          // Perform the transformation, placing the output in the DOMResult.
        transformer.transform(new DOMSource(doc), domResult);
          
            //Instantiate an XML serializer and use it to serialize the output 
DOM to System.out
            // using a default output format.
        Serializer serializer = SerializerFactory.getSerializer("xml");
        serializer.setOutputStream(System.out);
        serializer.asDOMSerializer().serialize(domResult.getNode());
        }
      else
      {
        throw new org.xml.sax.SAXNotSupportedException("DOM node processing not 
supported!");
      }
    }
  }
  
  
  
  1.1                  xml-xalan/java/samples/DOM2DOM/readme.html
  
  Index: readme.html
  ===================================================================
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  
  <html>
  <head>
        <title>Xalan Samples</title>
  </head>
  <body>
  <h2>Xalan Samples</h2>
  <p>For information about the samples (what they illustrate and how to run 
them), see <a href="../../docs/samples.html">Samples</a>.</p>
  
  
  </body>
  </html>
  
  
  

Reply via email to