File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes XML and Related Technologies and the fly likes I'm getting an error about my stylesheet missing the xsl:version attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "I Watch "I New topic
Author

I'm getting an error about my stylesheet missing the xsl:version attribute

Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
I am getting the following error:
javax.xml.transform.TransformerException: stylesheet requires attribute: version.
Looking at documents there seems to be two reasons why tou would get this error:
reason 1) Ensure the URI for the xsl namespace is "http://www.w3.org/1999/XSL/Transform".
But in my XSL style sheet I have the correct format:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<HEAD>
<TITLE>My Books</TITLE>
</HEAD>
<body bgcolor="lightslategray">
<table border="4">
<TR>
<TH>Category</TH>
<TH>Title</TH>
<TH>Author</TH>
<TH>Price</TH>
</TR>
<xsl:apply-templates select="books/book">
<xsl:sort select="@category"></xsl:sort>
</xsl:apply-templates>
</table>
</body>
</html>
</xsl:template>
<xsl:template match="books/book">
<TR>
<TD>
<xsl:value-of select="@category"></xsl:value-of>
</TD>
<TD>
<xsl:value-of select="./title"></xsl:value-of>
</TD>
<TD>
<xsl:value-of select="./author"></xsl:value-of>
</TD>
<TD>
<xsl:value-of select="./price"></xsl:value-of>
</TD>
</TR>
</xsl:template>
</xsl:stylesheet>
Reason 2 : The parser you are using to process a stylesheet Source and generate a Transformer does not have the namespaceAware property set to true.
But if you use a TransformerFactory to process a stylesheet Source and generate a Transformer, the TransformerFactory instructs the SAXParserFactory to set the parser's namespaceAware property to true. which is what I am using in my code:
package XSTLParser;
import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import java.io.File;
public class XSLTTest
{
public static void main(String[] args)
{
StreamSource source = null;
StreamResult result = null;

File filexml = new File("C://javabay/XSTLParser/books.xml");
File filexsl = new File("C://javabay/XSTLParser/books.xml");
if(!filexml.exists())
{
System.out.println("Cant find XML file");
return;
}
else if(!filexsl.exists())
{
System.out.println("Cant find XSL file");
return;
}
else
{
System.out.println("Found file");
source = new StreamSource(filexml);
result = new StreamResult(System.out);
}

TransformerFactory factory = TransformerFactory.newInstance();
try
{
Transformer transformer = factory.newTransformer(new StreamSource(filexsl));
//System.out.println("Call transformer");
//transformer.transform(source,result);
}
catch(TransformerConfigurationException tce)
{
tce.printStackTrace();
}
/* catch(TransformerException te)
{
te.printStackTrace();
}*/
}

}
Thanks for any help
Tony
Tony Evans
Ranch Hand

Joined: Jun 29, 2002
Posts: 573
Solved the problem, a copy and paste mistake, I have a reasonable excuse its very late in the UK.
Correct line of code is
File filexsl = new File("C://javabay/XSTLParser/book.xsl"); I was calling the XML file.
Tony
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I'm getting an error about my stylesheet missing the xsl:version attribute