Monday, May 3, 2010

XSLT Troubleshooting

May be it is just based on my experience, but I feel in general XSLT doesn’t have lot of troubleshooting support. E.g. in Java, no matter what JVM you use, you can pretty much get stack trace (even in NPE errors). In XSLT, based on XML parser you use, sometime you get line numbers and some time you don’t, plus it doesn't provide lot of details in log. Moreover there are not really any good tools to do much troubleshooting. In AIA world, it gets even crazier. Most of the XSLT functions come with AIA just runs only on server side, so you are hopeless and helpless when you want to do some troubleshooting on your local box. It gets even worse, when you get FOTY0001 type errors. Sometime you get more details in log file when there is FOTY0001, and sometime you don't.

Here are couples of ideas which can make your life easier.

1) XSL comment
You can put XSL comment in your code, so it will show up when XSLT is completed. It does help a lot when you are trying to just print values of variables. Pretty much all credit goes to Mahesh Narayanaswamy (absolute XSL genius) for this suggestion.

2) XSL out
This was very cool idea came out of disucssion with Amol Vaidya. XSL comment didn’t help much when XSLT was completely breaking and we were unable to get the line number or the root cause. All we needed is the similar capability like System.out inside the XSL, so we know how far in XSL we went and what are the variables. We just want to get all information before the point of failure. A custom XSLT log function came pretty handy for putting trace log in your XSLT. This way we can get as much information about the XSLT before the point of failure.
We wrote custom XSL function called XSLTLog, and registered that function in BPEL RT and ESB XSL Library.

3) Java code
I also wrote a Java code which can take XML input and execute the XSL. We have to register this Java code to the server as lot of AIA XSL functions relies on server side components. We also took it further to find exact line number in XSL using binary search approach.

2 comments:

Animesh said...

Chintan I really like your idea of using an instance of XSLTprocessor from the jar xmlparserv2.jar.But while processing the large XSL files that comes with the PIP I am having a trouble though I have included aia.jar and bpm-services.jar.For aia functions the getserviceproperty function is not able to find out the properties from AIAConfigurationProperties file and while xref is getting classIntializer error.I am really trying this badly for last one week.I can send you the code if you want to have a look on it.Any help will be really appreciated.
Thanks
Animesh Roy(ani.ju.it@gmail.com)

Chintan Shah said...

Hello Samrat,

It would be possible but it would be pretty hard to make it work as stand alone jar. You need to register JAR as well as find a way to register all XSL function to your stand alone JVM.

I used other approach, where I just wrote Java code and deploy that as WS on AIA box. so I still get all function from AIA server and get interface where I can plugin my xsl and xml and get what I want.

Feel free to send me your code chintanjshah@gmail.com and I can see if I can make it work.