Hi,
 
I am using xalan jar files for xsl transformation. I am using my custom class 
to call java method. It gives me below error if I add another node within 
/Doc:Document/Doc:camt.028.001.02/Doc:Assgnmt . Please see the attached file 
c.xml file 
 
SystemId Unknown; Line #0; Column #0; org.w3c.dom.DOMException: 
HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not 
permitted.
 
 
My classpath is 
/tmp/ajay/xslt/xalan.jar:/tmp/ajay/xslt/xml-apis.jar:/tmp/ajay/xslt/xercesImpl.jar:/tmp/ajay/xslt/serializer.jar:/tmp/ajay/xslt/Validator.class:.


Please find the attached java, xml and xsl files. I do not know what I am 
missing here. Is this a bug ? I am not sure. Please help me in resolving the 
issue.

Thanks
Ajay Bhadauria



      
<Doc:Document xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xmlns:Doc="urn:swift:xsd:swift.eni$camt.028.001.02">
	<Doc:camt.028.001.02>
		<Doc:Assgnmt>
			<Doc:country1>USA</Doc:country1>
			<Doc:country2>CHINA</Doc:country2>
			<Doc:country3>BELGIUM</Doc:country3>
		</Doc:Assgnmt>
	</Doc:camt.028.001.02>
</Doc:Document>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";  
                              xmlns:x="urn:swift:xsd:swift.eni$camt.028.001.02"
                              xmlns:java="xalan://Validator" >

        <xsl:output method="text" indent="no" />  

        <xsl:variable name="validatorObj" select="java:new()"/> 

        <xsl:template  match="/x:Document/x:camt.028.001.02/x:Assgnmt/x:country1" >
	      <xsl:variable name="p1" select="." />
              <xsl:variable name="t1" select="java:validateCountryCode($validatorObj, $p1)"/>
              <xsl:variable name="BR000" select="$t1 = 'T'"/>
          </xsl:template>

        <xsl:template  match="/x:Document/x:camt.028.001.02/x:Assgnmt/x:country2" >
	      <xsl:variable name="p1" select="." />
              <xsl:variable name="t1" select="java:validateCountryCode($validatorObj, $p1)"/>
              <xsl:variable name="BR000" select="$t1 = 'T'"/>
          </xsl:template>

</xsl:stylesheet>
import java.io.*;
import org.w3c.dom.* ;
import java.util.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.DOMResult ;
import javax.xml.transform.stream.StreamSource ;
import javax.xml.parsers.DocumentBuilderFactory ;
import javax.xml.parsers.DocumentBuilder ;
import javax.xml.parsers.ParserConfigurationException ;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult ;
import javax.xml.transform.sax.SAXResult ;
import org.xml.sax.helpers.DefaultHandler;
import org.xml.sax.InputSource;
import org.apache.xalan.transformer.TransformerImpl ;

public class  XmlTransform
{

     public static void main ( String [] args )
     {
               parseXmlFile(args[0],args[1]);             

     }

      public static void  parseXmlFile(String inFilename, String xslFilename) 
      {
        try {
            // Create transformer factory
            TransformerFactory factory = TransformerFactory.newInstance();
    
            // Use the factory to create a template containing the xsl file
            Templates template = factory.newTemplates(new StreamSource( new 
FileInputStream(xslFilename)));

    
            // Use the template to create a transformer
            Transformer xformer = null ;
            try
            {
              xformer = template.newTransformer();
            }
            catch(Exception e)
            {
               System.out.println(e.toString());
            }
    
            // Create a new document to hold the results

            DocumentBuilderFactory dFactory = 
DocumentBuilderFactory.newInstance();
            dFactory.setNamespaceAware(true);
            dFactory.setValidating(false);
            dFactory.setIgnoringElementContentWhitespace(true);
            dFactory.setIgnoringComments(true);

            DocumentBuilder dBuilder = dFactory.newDocumentBuilder();
            Document doc = dBuilder.newDocument();
            Document document= null;

            try
            {
                document = dBuilder.parse( new FileInputStream(inFilename));
            }
            catch( Exception e)
            {
               System.out.println(e.toString());

            }

            Source source = new DOMSource( document );
            Result result = new DOMResult( doc );
            System.out.println("debug1");
            xformer.transform( source,result);
            System.out.println("debug2");
            
           
        } catch (ParserConfigurationException e) 
        {
            System.out.println("debug3");
            System.out.println(e.toString());
        } 
        catch (FileNotFoundException e) 
        {
            System.out.println("debug4");
            System.out.println(e.toString());
        } catch (TransformerConfigurationException e) 
        {
         
           System.out.println(e.toString());
       
        } catch (TransformerException e) 
        {
           
           System.out.println(e.toString());
        }
    }

}

Attachment: XmlTransform.class
Description: application/java

Reply via email to