Создайте пользовательский резолвер, чтобы разрешить из набора путей к классам, что для Transfromer, чтобы проверить, у меня был файл jar, заданный в classpath в проекте eclipse
весь код приведен ниже ----- пример запуска ------------- `
public class RunTransform {
public static void main(String[] args) {
// SimpleTransform.transform("xsl/SentAdapter.xsl", "C:/Amin/AllWorkspaces/ProtoTypes/XsltDemo/xml/acc.xml");
SimpleTransform.transform("xslt/ibanvalidation/accuity-ibanvalidationresponse.xsl", "C:/Amin/AllWorkspaces/ProtoTypes/XsltDemo/xml/acc.xml");
}
}
-----------Sample transfomring example ----------------
package com;
import java.io.File;
import java.io.FileOutputStream;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class SimpleTransform {
public static void transform(String xslName,String xmlName) {
try {
ResourceResolver resloader = new ResourceResolver();
TransformerFactory tFactory = TransformerFactory.newInstance();
tFactory.setURIResolver(resloader);
StreamSource xsltSRC = new StreamSource(resloader.resolve(xslName));
Transformer transformer = tFactory.newTransformer(xsltSRC);
StreamSource xmlSSRC = new StreamSource(xmlName);
System.out.println("Streamm sources created .....");
System.out.println("XSLT SET ....");
transformer.transform(xmlSSRC, new StreamResult(new FileOutputStream(new File("C:/Amin/AllWorkspaces/ProtoTypes/XsltDemo/xml/result.xml"))));
System.out.println("Finished transofrmation ..........");
System.out.println("************* The result is out in respoinse *************");
} catch (Throwable t) {
t.printStackTrace();
}
}
}
`
----------- Код для пользовательского распознавателя --------------- `
package com;
import javax.xml.transform.URIResolver;
import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
import javax.xml.transform.stream.StreamSource;
import java.io.InputStream;
import java.net.URL;
import java.util.Enumeration;
import java.util.Iterator;
public class ResourceResolver implements URIResolver {
/* (non-Javadoc)
* @see javax.xml.transform.URIResolver#resolve(java.lang.String, java.lang.String)
*/
public Source resolve(String href, String base) throws TransformerException {
try {
InputStream is = ClassLoader.getSystemResourceAsStream(href);
return new StreamSource(is, href);
} // try
catch (Exception ex) {
throw new TransformerException(ex);
} // catch
} // resolve
/**
* @param href
* @return
* @throws TransformerException
*/
public InputStream resolve(String href) throws TransformerException {
try {
InputStream is = ClassLoader.getSystemResourceAsStream(href);
return is;
} // try
catch (Exception ex) {
throw new TransformerException(ex);
} // catch
}
} // ResourceResolver
`