Exception javax.xml.transform.TransformerConfigurationException - with StAXSource
to reproduce try out the sample testcase attached
javac Test1.java (set classpath to jaxp1.4 jars)
java -Djava.endorsed.dirs=${jaxp14_jars} Test1
Error Message :
Exception javax.xml.transform.TransformerConfigurationException: Only StreamSource, SAXSource and DOMSource are supported by XSLTC
---------------------------- Test case ------------------------------
import java.io.*;
import javax.xml.stream.*;
import javax.xml.stream.events.*;
import javax.xml.transform.*;
import javax.xml.transform.stax.*;
public class Test1 {
XMLInputFactory ifac = XMLInputFactory.newInstance();
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
public static void main(String args[]){
// try{
Test1 t1 = new Test1();
t1.test05();
}
public void test05() {
try{
XMLStreamReader reader = ifac.createXMLStreamReader(new FileInputStream("cities.xml"));
StAXSource src = new StAXSource(reader);
XMLStreamWriter writer = ofac.createXMLStreamWriter(new FileOutputStream("cities05.out"));
StAXResult res = new StAXResult(writer);
TransformerFactory tfactory5 = TransformerFactory.newInstance();
XMLStreamReader reader1 = ifac.createXMLStreamReader(new FileInputStream("cities.xsl"));
StAXSource src1 = new StAXSource(reader1);
System.out.println("before newTransformer");
Transformer transformer = tfactory5.newTransformer(src1);
System.out.println("before setOutputProperty");
transformer.setOutputProperty("indent", "yes");
transformer.transform( src, res);
}
catch(Exception e){
System.out.println("Exception " + e);
}
}
}
---------------------------- cities.xml ------------------------------
<?xml version="1.0" standalone="yes" ?>
<cities>
<city name="Paris" country="France"/>
<city name="Roma" country="Italia"/>
<city name="Nice" country="France"/>
<city name="Madrid" country="Espana"/>
<city name="Milano" country="Italia"/>
<city name="Firenze" country="Italia"/>
<city name="Napoli" country="Italia"/>
<city name="Lyon" country="France"/>
<city name="Barcelona" country="Espana"/>
</cities>
-------------------------------- cities.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="/">
<xsl:variable name="unique-countries"
select="/cities
/city[not(@country=preceding-sibling::city/@country)]
/@country"
/>
<countries>
<xsl:for-each select="$unique-countries">
<country name="{.}">
<xsl:for-each select="//city[@country=current()]">
<city><xsl:value-of select="@name"/></city>
</xsl:for-each>
</country>
</xsl:for-each>
</countries>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------------------
###@###.### 2005-07-20 07:23:22 GMT
to reproduce try out the sample testcase attached
javac Test1.java (set classpath to jaxp1.4 jars)
java -Djava.endorsed.dirs=${jaxp14_jars} Test1
Error Message :
Exception javax.xml.transform.TransformerConfigurationException: Only StreamSource, SAXSource and DOMSource are supported by XSLTC
---------------------------- Test case ------------------------------
import java.io.*;
import javax.xml.stream.*;
import javax.xml.stream.events.*;
import javax.xml.transform.*;
import javax.xml.transform.stax.*;
public class Test1 {
XMLInputFactory ifac = XMLInputFactory.newInstance();
XMLOutputFactory ofac = XMLOutputFactory.newInstance();
public static void main(String args[]){
// try{
Test1 t1 = new Test1();
t1.test05();
}
public void test05() {
try{
XMLStreamReader reader = ifac.createXMLStreamReader(new FileInputStream("cities.xml"));
StAXSource src = new StAXSource(reader);
XMLStreamWriter writer = ofac.createXMLStreamWriter(new FileOutputStream("cities05.out"));
StAXResult res = new StAXResult(writer);
TransformerFactory tfactory5 = TransformerFactory.newInstance();
XMLStreamReader reader1 = ifac.createXMLStreamReader(new FileInputStream("cities.xsl"));
StAXSource src1 = new StAXSource(reader1);
System.out.println("before newTransformer");
Transformer transformer = tfactory5.newTransformer(src1);
System.out.println("before setOutputProperty");
transformer.setOutputProperty("indent", "yes");
transformer.transform( src, res);
}
catch(Exception e){
System.out.println("Exception " + e);
}
}
}
---------------------------- cities.xml ------------------------------
<?xml version="1.0" standalone="yes" ?>
<cities>
<city name="Paris" country="France"/>
<city name="Roma" country="Italia"/>
<city name="Nice" country="France"/>
<city name="Madrid" country="Espana"/>
<city name="Milano" country="Italia"/>
<city name="Firenze" country="Italia"/>
<city name="Napoli" country="Italia"/>
<city name="Lyon" country="France"/>
<city name="Barcelona" country="Espana"/>
</cities>
-------------------------------- cities.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="/">
<xsl:variable name="unique-countries"
select="/cities
/city[not(@country=preceding-sibling::city/@country)]
/@country"
/>
<countries>
<xsl:for-each select="$unique-countries">
<country name="{.}">
<xsl:for-each select="//city[@country=current()]">
<city><xsl:value-of select="@name"/></city>
</xsl:for-each>
</country>
</xsl:for-each>
</countries>
</xsl:template>
</xsl:stylesheet>
------------------------------------------------------------------
###@###.### 2005-07-20 07:23:22 GMT