Discussion:
[saxon] saxon8.jar XSLT 2.0 processor problem
Diego López
2007-02-20 10:13:04 UTC
Permalink
Hi,
I can't solve the problem with these stylesheets. They have to be
procssed with XSLT 2.0 processor. They were generated with Altova
StyleVision. I have download a java library called saxon8.jar but it
doesn't work.This is my java program test to do this task:


System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, new StreamResult("C:/salida.html"));

I will be very grateful if someone could help me. I am stopped with
this since many days ago.
I enclose the problematic files.
Regards,
Diego
Abel Braaksma
2007-02-20 10:31:19 UTC
Permalink
Hi Diego,

What is the error you receive? It will help a lot if you create a
minimum working set that illustrates your problem. I.e., a small but
clear XML file, a small XSLT file illustrating your problem and what you
expect it to produce (i.e., what it used to produce before running with
Saxon).

You say you have used Altova Stylevision. Be aware that Altova is still
very far from being compliant to the specs (even though they claim
differently). It is likely that your xslt stylesheet contains
non-conformant instructions (which is why we need to have a look at your
stylesheet).

Of course, attachments are not passed on by the mailer, too dangerous
and they won't work for the archives. XSLT and XML are plain text, you
can simply copy them into the message.

Cheers,
-- Abel
Post by Diego López
Hi,
I can't solve the problem with these stylesheets. They have to be
procssed with XSLT 2.0 processor. They were generated with Altova
StyleVision. I have download a java library called saxon8.jar but it
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, new StreamResult("C:/salida.html"));
I will be very grateful if someone could help me. I am stopped with
this since many days ago.
I enclose the problematic files.
Regards,
Diego
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
saxon-help mailing list
https://lists.sourceforge.net/lists/listinfo/saxon-help
Angus Rose
2007-02-22 09:30:25 UTC
Permalink
Hi,
I had a similar problem when I started to use Saxon. I've pasted my code below to show what I had to do to fix it. It's basically due to Saxon supporting URIs rather than filenames.

public void createStylesheetCache(String l_strxslLocat, String l_strxmlLocat, String l_strxmlOutput)
{
System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl");

File xmlFile = new File(l_strxmlLocat);
File xsltFile = new File(l_strxslLocat);

try {

xmlSource = new ResourceResolver().resolve(l_strxmlLocat , this.getM_strXMLBaseDir());
xsltSource = new ResourceResolver().resolve(l_strxslLocat , this.getM_strXSLBaseDir());

} catch (TransformerException e) {

e.printStackTrace();

}

String fileName = l_strxmlOutput;
File fileObject = new File(fileName);
//SAXON specific code for output. SAXON supports URIs ratther than filenames
URL fileURL = null;
try {
fileURL = fileObject.toURL( );
} catch (MalformedURLException e) {
e.printStackTrace();
}
String systemID = fileURL.toExternalForm( );
System.out.println(systemID);
xmlOutput = new StreamResult(systemID);

tFactory = TransformerFactory.newInstance();

try
{
cachedXSLT = tFactory.newTemplates(xsltSource);
tTransformer = cachedXSLT.newTransformer();
tTransformer.setParameter("input" , xmlSource );
}
catch (TransformerConfigurationException e)
{
m_attillaStkTcePrinter.doStackTracePrintout(e);
e.printStackTrace();
}
}

public void doTransform()
{

try
{

tTransformer.transform(xmlSource , xmlOutput);

}
catch (TransformerConfigurationException e)
{
m_attillaStkTcePrinter.doStackTracePrintout(e);
System.out.println("TransformerConfigurationException in XSLTTransformer.doTransform()");
e.printStackTrace();

}
catch (TransformerException e)
{
m_attillaStkTcePrinter.doStackTracePrintout(e);
System.out.println("TransformerException in XSLTTransformer.doTransform()");
e.printStackTrace();
}
}


Good luck

Angus


-----Original Message-----
From: saxon-help-***@lists.sourceforge.net on behalf of Diego López
Sent: Tue 20/02/2007 10:13
To: saxon-***@lists.sourceforge.net
Subject: [saxon] saxon8.jar XSLT 2.0 processor problem

Hi,
I can't solve the problem with these stylesheets. They have to be
procssed with XSLT 2.0 processor. They were generated with Altova
StyleVision. I have download a java library called saxon8.jar but it
doesn't work.This is my java program test to do this task:


System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
trans.transform(xmlSource, new StreamResult("C:/salida.html"));

I will be very grateful if someone could help me. I am stopped with
this since many days ago.
I enclose the problematic files.
Regards,
Diego

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Owen Rees
2007-02-22 11:00:36 UTC
Permalink
Post by Angus Rose
I had a similar problem when I started to use Saxon. I've pasted my
code below to show what I had to do to fix it. It's basically due to
Saxon supporting URIs rather than filenames.
See the JAXP 1.3 specification - quoted directly in the J2SE documentation:

StreamResult

public StreamResult(String systemId)

Construct a StreamResult from a URL.

Parameters:
systemId - Must be a String that conforms to the URI syntax.

This can be found at
<http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/transform/stream/StreamResult.html#StreamResult(java.lang.String)>

The JAXP specification is not very clear about what should happen if the
string is not a URI but anything that implements the JAXP spec is just
wrong if it does not try interpret the string as a URI first.

If you want to use a filename, you could make a File object and use the
StreamResult(File f) constructor. This will set the SystemID to be the
proper file: URI.
--
Owen Rees
Hewlett Packard Laboratories, Bristol, UK
Loading...