You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by st...@jpmchase.com on 2007/12/11 17:09:58 UTC

Issue trying to extract errors from XSLTs in Java

Hi,

I am having an issue when I attempt to throw an error from a stylesheet, 
terminate, and then capture the error in a TransformerException in Java 
and extact it into a meaningful error message.  I checked the mailing 
archive and it was suggested in 2002 that this functionality could be 
implemented: 

http://marc.info/?l=xalan-j-users&m=103417059423384&w=2

I have tried the following with an older version of xalan and xerces, but 
also the latest (just downloaded xalan 2.7.1 and xerces 2.9.0)

So here is my code.  In my stylesheet I throw an error for whatever 
reason: 

<xsl:message terminate="yes">Error thrown</xsl:message>

And in my Java code I attempt to catch and extact the error message:

} catch (TransformerException e) { 
        log.debug("Exception Caught during XSLT processing.  Message: " + 
e.getMessage() + ", Location: " + e.getLocationAsString());
}

The following line is printed out, but I don't know where from.  I need to 
capture this information and log it:

file:///C:/xxx/xxx.xsl; Line #171; Column #35; Error thrown

None of the methods on the TransformerException object return this 
information.  The only piece of information I get back regarding the error 
is returned from getMessage():

Stylesheet directed termination

Am I doing anything wrong, or is what I am trying to do unachievable?

Many thanks in advance,
Stephen
Stephen P Harper 
PTP Feeds Build
GDP 228 5706 | Direct +44 141 228 5706 | Email 
Stephen.P.Harper@jpmchase.com 


-----------------------------------------
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to UK legal entities.

Re: Issue trying to extract errors from XSLTs in Java

Posted by st...@jpmchase.com.
Hi Henry,

That's worked.  Thank you so much.

Stephen
Stephen P Harper 
PTP Feeds Build
GDP 228 5706 | Direct +44 141 228 5706 | Email 
Stephen.P.Harper@jpmchase.com 




Henry Zongaro <zo...@ca.ibm.com> 
13/12/2007 14:35

To
stephen.p.harper@jpmchase.com
cc
xalan-j-users@xml.apache.org
Subject
Re: Issue trying to extract errors from XSLTs in Java







Hi, Stephen. 

stephen.p.harper@jpmchase.com wrote on 2007-12-11 11:09:58 AM: 
> So here is my code.  In my stylesheet I throw an error for whatever 
reason: 
> 
> <xsl:message terminate="yes">Error thrown</xsl:message> 
> 
> And in my Java code I attempt to catch and extact the error message: 
> 
> } catch (TransformerException e) { 
>         log.debug("Exception Caught during XSLT processing. 
> Message: " + e.getMessage() + ", Location: " + e.getLocationAsString()); 

> } 
> 
> The following line is printed out, but I don't know where from.  I 
> need to capture this information and log it: 
> 
> file:///C:/xxx/xxx.xsl; Line #171; Column #35; Error thrown 

The Xalan-J processors report the message produced for an xsl:message 
instruction ("Error thrown" in this case) through the "warning" method of 
any ErrorListener installed on the Transformer.  The effect of the 
termination is then reported through ErrorListener.fatalError (with the 
message "Stylesheet directed termination").  If you install an 
ErrorListener, you should be able to log the messages received through any 
of the three methods. 

You can use TransformerException.getLocationAsString() or 
TransformerException.getMessageAndLocation() to get the system ID, line 
and column number of the xsl:message. 

I hope that helps. 

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      XSLT Processors Development
IBM SWS Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com


-----------------------------------------
This communication is for informational purposes only. It is not
intended as an offer or solicitation for the purchase or sale of
any financial instrument or as an official confirmation of any
transaction. All market prices, data and other information are not
warranted as to completeness or accuracy and are subject to change
without notice. Any comments or statements made herein do not
necessarily reflect those of JPMorgan Chase & Co., its subsidiaries
and affiliates.

This transmission may contain information that is privileged,
confidential, legally privileged, and/or exempt from disclosure
under applicable law. If you are not the intended recipient, you
are hereby notified that any disclosure, copying, distribution, or
use of the information contained herein (including any reliance
thereon) is STRICTLY PROHIBITED. Although this transmission and any
attachments are believed to be free of any virus or other defect
that might affect any computer system into which it is received and
opened, it is the responsibility of the recipient to ensure that it
is virus free and no responsibility is accepted by JPMorgan Chase &
Co., its subsidiaries and affiliates, as applicable, for any loss
or damage arising in any way from its use. If you received this
transmission in error, please immediately contact the sender and
destroy the material in its entirety, whether in electronic or hard
copy format. Thank you.

Please refer to http://www.jpmorgan.com/pages/disclosures for
disclosures relating to UK legal entities.

Re: Issue trying to extract errors from XSLTs in Java

Posted by Henry Zongaro <zo...@ca.ibm.com>.
Hi, Stephen.

stephen.p.harper@jpmchase.com wrote on 2007-12-11 11:09:58 AM:
> So here is my code.  In my stylesheet I throw an error for whatever 
reason: 
> 
> <xsl:message terminate="yes">Error thrown</xsl:message> 
> 
> And in my Java code I attempt to catch and extact the error message: 
> 
> } catch (TransformerException e) { 
>         log.debug("Exception Caught during XSLT processing. 
> Message: " + e.getMessage() + ", Location: " + e.getLocationAsString()); 

> } 
> 
> The following line is printed out, but I don't know where from.  I 
> need to capture this information and log it: 
> 
> file:///C:/xxx/xxx.xsl; Line #171; Column #35; Error thrown 

The Xalan-J processors report the message produced for an xsl:message 
instruction ("Error thrown" in this case) through the "warning" method of 
any ErrorListener installed on the Transformer.  The effect of the 
termination is then reported through ErrorListener.fatalError (with the 
message "Stylesheet directed termination").  If you install an 
ErrorListener, you should be able to log the messages received through any 
of the three methods.

You can use TransformerException.getLocationAsString() or 
TransformerException.getMessageAndLocation() to get the system ID, line 
and column number of the xsl:message.

I hope that helps.

Thanks,

Henry
------------------------------------------------------------------
Henry Zongaro      XSLT Processors Development
IBM SWS Toronto Lab   T/L 313-6044;  Phone +1 905 413-6044
mailto:zongaro@ca.ibm.com