code: private static void instrumentTransformer(Transformer transformer) throws Exception {
          transformer.setErrorListener(new TransformerErrorListener());
  
          if (transformer instanceof TransformerHandler) {
              transformer = ((TransformerHandler) transformer).getTransformer();
          }
          if (transformer instanceof TransformerImpl) {
              final TraceManager tm = ((TransformerImpl) transformer).getTraceManager();
              final PrintTraceListener ptl = new PrintTraceListener(new PrintWriter(System.out));
              // Print information as each node is 'executed' in the stylesheet.
              ptl.m_traceElements = true;
              // Print information after each result-tree generation event.
              ptl.m_traceGeneration = true;
              // Print information after each selection event.
              ptl.m_traceSelection = true;
              // Print information whenever a template is invoked.
              ptl.m_traceTemplates = true;
              // Print information whenever an extension call is made.
              ptl.m_traceExtension = true;
              tm.addTraceListener(ptl);
          }
      }
docs: Adds a little verbosity to a constructed <code>Transformer</code>.
  
  @param transformer
  The <code>Transformer</code> which may produce some output.
  @throws Exception
  If setting/adding a listener gives a problem.