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

Malachi de AElfweald malachi at tremerechantry.com
Thu Oct 10 22:31:53 PDT 2002

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)
			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());
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"/>

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 -->
    <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 match="*">
          <DIV STYLE="margin-left:2em; color:#003366">
            &lt;<xsl:node-name/><xsl:apply-templates select="@*"/>/&gt;

        <xsl:template match="*[node()]">
          <DIV STYLE="margin-left:2em">
            <SPAN STYLE="color:#003366">&lt;<xsl:node-name/><xsl:apply-templates select="@*"/>&gt;</SPAN><xsl:apply-templates 
select="node()"/><SPAN STYLE="color:#003366">&lt;/<xsl:node-name/>&gt;</SPAN>

        <xsl:template match="@*">
          <SPAN STYLE="color:green"> <xsl:node-name/>="<SPAN STYLE="color:red"><xsl:value-of /></SPAN>"</SPAN>

        <xsl:template match="pi()">
          <DIV STYLE="margin-left:2em; color:maroon">&lt;?<xsl:node-name/><xsl:apply-templates select="@*"/>?&gt;</DIV>

        <xsl:template match="cdata()"><pre>&lt;![CDATA[<xsl:value-of />]]&gt;</pre></xsl:template>

        <xsl:template match="textNode()"><xsl:value-of /></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.TransformerConfigurationException: 
>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 ByteBuffer....
>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 this?
>			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