[jdom-interest] TransformerException: stylesheet requires attribute: version

Malachi de AElfweald malachi at tremerechantry.com
Thu Oct 10 22:52:20 PDT 2002

Further testing also shows this:

with TransformerException being found in rt.jar (xalan.jar is in ext):

E:\malachi\projects>java -cp classes org.eoti.util.xml.XMLFile pandora.xml xml2h
This line will kill it.
Exception: javax.xml.transform.TransformerConfigurationException: javax.xml.tran
sform.TransformerException: org.jdom.JDOMException: Exception in startElement: s
tylesheet requires attribute: version; Missing or incorrect XSLT Namespace. : st
ylesheet requires attribute: version

with TransformerException being found in xalan.jar (xalan.jar in endorsed):

E:\malachi\projects>java -cp classes org.eoti.util.xml.XMLFile pandora.xml xml2h
This line will kill it.
SystemId Unknown; Line -1; Column -1; Exception: Exception in startElement: styl
esheet requires attribute: version

BTW: This is JDK1.4

10/10/2002 10:31:53 PM, Malachi de AElfweald <malachi at tremerechantry.com> wrote:

>Just to clarify other issues that might be involved....
>The example below givesthis error message:
>This line will kill it.
>Exception: javax.xml.transform.TransformerConfigurationException: javax.xml.tran
>sform.TransformerException: org.jdom.JDOMException: Exception in startElement: s
>tylesheet requires attribute: version; Missing or incorrect XSLT Namespace. : st
>ylesheet requires attribute: version
>I tried to narrow the problem down.... it seems that JDOM does not correctly handle
>the xsl namespace, or I am missing something completely obvious...  This error occurs
>in non-JDOM stuff when setNamespaceAware(true) is not set... however, with JDOM, I
>don't know how to set that.  I verified that the Documents were JDOM documents by
>doing System.out.println("DOC: " + in.getClass())....  Neither the JDOMSource or StreamSource
>worked, but StreamSource stopped before "Missing or incorrect", whether it used new File(args[1])
>or just args[1]....
>I also tried (in case the error was the url):
><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XML/Transform">
>   public static void main(String[] args)
>   {
>		try{
>			SAXBuilder builder = new SAXBuilder();
>			Document in = builder.build(args[0]);
>			Document out = builder.build(args[1]);
>			JDOMSource ss = new JDOMSource(out);
>//			StreamSource ss = new StreamSource(new File(args[1]));
>			System.out.println ("This line will kill it.");
>			Transformer transformer = TransformerFactory.newInstance().newTransformer(ss);
>			System.out.println ("Didn't get here, did you?");
>// rest ripped out till we fix this part
>		}catch (Exception e) {
>			System.out.println("Exception: " + e.getMessage());
>			System.exit(0);
>		}
>   }
>java -cp classes org.eoti.util.xml.XMLFile pandora.xml xml2html.xsl
><?xml version="1.0" encoding="UTF-8"?>
><?xml-stylesheet type="text/xsl" href="xml2html.xsl"?>
><!-- This file is only intended for testing XMLMod, it isn't live -->
><!-- Author: Malachi de AElfweald -->
><!DOCTYPE pandora SYSTEM "pandora.dtd">
>	<service name="httpd" port="80" base="E:\malachi\projects\www" verbose="true">
>		<module class="org.eoti.pandora.modules.XMLMod"/>
>		<module class="org.eoti.pandora.modules.JavaExecMod"/>
>		<module class="org.eoti.pandora.modules.InternalServicesMod"/>
>		<module class="org.eoti.pandora.modules.StaticContentMod"/>
>	</service>
>xml2html.xsl (found online and added the version="1.0" to the xsl:stylesheet):
><?xml version="1.0"?>
><!-- Generic stylesheet for viewing XML -->
><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/TR/WD-xsl">
>  <!-- This template will always be executed, even if this stylesheet is not run on the document root 
>  <xsl:template>
>    <DIV STYLE="font-family:Courier; font-size:10pt; margin-bottom:2em">
>      <!-- Scoped templates are used so they don't interfere with the "kick-off" template. -->
>      <xsl:apply-templates select=".">
>        <xsl:template><xsl:apply-templates/></xsl:template>
>        <xsl:template match="*">
>          <DIV STYLE="margin-left:2em; color:#003366">
>            &lt;<xsl:node-name/><xsl:apply-templates select="@*"/>/&gt;
>          </DIV>
>        </xsl:template>
>        <xsl:template match="*[node()]">
>          <DIV STYLE="margin-left:2em">
>            <SPAN STYLE="color:#003366">&lt;<xsl:node-name/><xsl:apply-templates select="@*"/>&gt;
>select="node()"/><SPAN STYLE="color:#003366">&lt;/<xsl:node-name/>&gt;</SPAN>
>          </DIV>
>        </xsl:template>
>        <xsl:template match="@*">
>          <SPAN STYLE="color:green"> <xsl:node-name/>="<SPAN STYLE="color:red"><xsl:value-of />
>        </xsl:template>
>        <xsl:template match="pi()">
>          <DIV STYLE="margin-left:2em; color:maroon">&lt;?<xsl:node-name/><xsl:apply-templates 
>        </xsl:template>
>        <xsl:template match="cdata()"><pre>&lt;![CDATA[<xsl:value-of />]]&gt;</pre></xsl:template>
>        <xsl:template match="textNode()"><xsl:value-of /></xsl:template>
>      </xsl:apply-templates>
>    </DIV>
>  </xsl:template>
>10/10/2002 8:23:11 PM, Malachi de AElfweald <malachi at tremerechantry.com> wrote:
>>I am getting the following error.
>>org.jdom.JDOMException: XSLT Transformation failed: 
>>javax.xml.transform.TransformerException: javax.xml.transform.TransformerException: stylesheet 
requires attribute: version
>>Looking online, everyone said I had to set DocumentFactory.setNamespaceAware(true) to get rid of that 
error. But I am not 
>>using DocumentFactory, since I just using JDOM's SAXBuilder...
>>My transform routine needs to return a char[] so I can create a CharBuffer to create an NIO 
>>Here's my transform routine that is causing the problem...
>>	public char[] transform(InputStream stylesheet)
>>	throws JDOMException
>>	{
>>		try{
>>			CharArrayWriter output = new CharArrayWriter();
>>			StreamSource ss = new StreamSource(stylesheet);
>>			Transformer transformer = TransformerFactory.newInstance().newTransformer(ss);
>>//Properties p = transformer.getOutputProperties();
>>//p.store(new FileOutputStream("transformer.prop"), "Transformer Configuration");
>>			StreamResult out = new StreamResult(output);
>>//			JDOMResult out = new JDOMResult(); // output may not be well-formed XML, so can't use 
>>			transformer.transform(new JDOMSource(doc), out);
>>			output.flush();
>>			return output.toCharArray();
>>	    }catch (Exception e) {
>>	    	throw new JDOMException("XSLT Transformation failed", e);
>>	    }
>>	}
>>Any help would be greatly appreciated...
>>To control your jdom-interest membership:

More information about the jdom-interest mailing list