我想在調用我的變換時捕獲java中的xsl:message。以下是我的代碼片段。在java中捕獲xsl:消息輸出
final ArrayList<TransformerException> errorList = new ArrayList<TransformerException>();
ErrorListener errorListener = new ErrorListener() {
@Override
public void warning(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
log.error(e.getMessage());
errorList.add(e);
}
@Override
public void error(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
log.error(e.getMessage());
errorList.add(e);
}
@Override
public void fatalError(TransformerException e) throws TransformerException {
//To change body of implemented methods use File | Settings | File Templates.
errorList.add(e);
throw e;
}
};
...
try
{
transformer.setErrorListener(errorListener);
newDoc = transform(transformer, oldDoc);
}
catch (TransformerException e) {
log.error("Problem transforming normalized document into PUBS-XML", e);
throw e;
}
不幸的是,這是行不通的。
有沒有更好的方法?
在此先感謝!
您正在使用哪種xslt處理器? – 2011-01-14 20:32:42
相信我在javax.xml.transform。*中使用Xalan。我的樣式表是版本2. – 2011-01-14 20:59:36