Project

Profile

Help

XSLT Code Coverage using Saxon trace output?

Added by Anubhuti Gautam 9 months ago

Hi Folks,

I am able to get the trace in an xml using Saxon. I am looking to get the code coverage of my XSLT which is being run & for which the trace is generated. Final output needed is to know the number of lines/total Lines *100.

Can someone help here if that has already been achieved. Or if there is an alternate approach apart from Saxon.


Replies (7)

Please register to reply

RE: XSLT Code Coverage using Saxon trace output? - Added by Michael Kay 9 months ago

We don't have a tool that does this directly.

You might find that the timing profile (-TL) gives you output that is more geared towards this requirement than the regular -T output - at any rate, it gives you execution counts for every top-level template and function.

If you don't mind doing some coding, you could write your own TraceListener, using the TimingTraceListener as a guide, to give output that is more focused on your requirement.

Amanda Galtman seems to have been trying to achieve similar things: see the issue she raised at https://saxonica.plan.io/issues/6302. I think she has been trying to put the output of -T tracing through an XML parser, and hitting problems because it isn't actually well-formed XML - it makes no attempt, for example, to close element tags properly in the event of a try/catch being executed.

RE: XSLT Code Coverage using Saxon trace output? - Added by Anubhuti Gautam 9 months ago

using -TL command gives error - Command line option -TL is not recognized.

my command looks something like this : java -jar c:\SaxonEE\SaxonEE12-4J\saxon-ee-12.4.jar -opt:0 -TL -Tlevel:high -xsl:transform.xsl -s:input.xml -o:output.xml 2>trace-transform.xml

Also one more question : why the -TP:trace.html & 2>trace-transform.xml does not work together

RE: XSLT Code Coverage using Saxon trace output? - Added by Michael Kay 9 months ago

Sorry, I meant -TP.

When you say these options don't work together, what results would you expect and how does it fail?

RE: XSLT Code Coverage using Saxon trace output? - Added by Anubhuti Gautam 9 months ago

Here I expect the trace to be written in an xml which is done using 2>trace-transform.xml The Profiling details on how much time spent on each xsl is done using -TP:trace.html

When I used these 2 together, it gives an error while if used individually, I get trace as well as Profiling.

RE: XSLT Code Coverage using Saxon trace output? - Added by Martin Honnen 9 months ago

Can you tell us exactly which error message you get? Is that a Saxon error message or one from the command shell? Is that on Windows? Is that a cmd shell or a Powershell shell you use?

RE: XSLT Code Coverage using Saxon trace output? - Added by Michael Kay 9 months ago

The parameter 2>trace-transform.xml is simply an instruction to the command line processor to redirect standard error output to a named file. It isn't even passed to Saxon and it doesn't change Saxon's behaviour in any way. To switch tracing on you need the -T option.

I believe you can probably attach two TraceListeners to the same transformation using the Java API, but you can't do it from the command line.

RE: XSLT Code Coverage using Saxon trace output? - Added by Christophe Marchand 8 months ago

Have a look at XSpec implementation, which provides code coverage for unit tests : https://github.com/xspec/xspec/tree/master/java

Main class produces an XML file, and then, combined with source XSLT, another XSL produces code coverage visualization (https://github.com/xspec/xspec/blob/master/src/reporter/coverage-report.xsl)

Best regards, Christophe

    (1-7/7)

    Please register to reply