public static Expression makeTraceInstruction(StyleElement source, Expression child) {
if (child instanceof TraceExpression && !(source instanceof StylesheetProcedure)) {
return child;
// this can happen, for example, after optimizing a compile-time xsl:if
}
CodeInjector injector = ((XSLTTraceListener)LogController.getTraceListener()).getCodeInjector();
int construct = source.getFingerprint();
StructuredQName qName;
if (source instanceof LiteralResultElement) {
construct = Location.LITERAL_RESULT_ELEMENT;
qName = source.getNamePool().getStructuredQName(source.getNameCode());
} else {
qName = source.getObjectName();
}
Expression tracer = injector.inject(child, source.getStaticContext(), construct, qName);
tracer.setSourceLocator(source);
return tracer;
}