I was working on this a bit in November but couldn't get anywhere with it. It is now causing me a serious roadblock. I've simplified things significantly to illustrate the problem. When I run this stylehseet:
 
<?xml version="1.0"?>
<
xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    <xsl:character-map name="htmlchars">
        <xsl:output-character character="&#x2002;" string="&amp;nbsp;" />
        <xsl:output-character character="&#x2003;" string="&amp;nbsp;" />
        <xsl:output-character character="&#x2007;" string="&amp;nbsp;" />
    </xsl:character-map>

    <xsl:output indent="yes" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" encoding="us-ascii" method="html" omit-xml-declaration="yes" use-character-maps="htmlchars" version="4.0"/>
    
    <xsl:template match="/">
        <html><head><title>test charmap</title></head>
        <body>
        <p>this is a test of chapmaps</p>
        </body>
        </html>
    </xsl:template>

<
/xsl:stylesheet>

Through this java:
 
package gov.irs.TFPOnlineProcessing;
 
import java.io.File;
 
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.QName;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Serializer;
import net.sf.saxon.s9api.XdmAtomicValue;
import net.sf.saxon.s9api.XdmNode;
import net.sf.saxon.s9api.XdmValue;
import net.sf.saxon.s9api.XsltCompiler;
import net.sf.saxon.s9api.XsltExecutable;
import net.sf.saxon.s9api.XsltTransformer;
 
public class SimpleTrans {
 
 static final String version = "$Revision: 1.1 $";
 /**
  * @param args
  */
 public static void main(String[] args) {
  // TODO Auto-generated method stub
  try {
  Processor proc = new Processor(false);
  XsltCompiler comp = proc.newXsltCompiler();
  XdmNode ss = proc.newDocumentBuilder().build(new File("C:/lib/xslt/charmap-test.xsl"));
  XsltExecutable exp = comp.compile(ss.asSource());
  XdmNode source = proc.newDocumentBuilder().build(new File("c:/htmlinput/p17.dxml"));
  Serializer out = new Serializer();
  //out.setOutputProperty(Serializer.Property.METHOD, "xml");
  out.setOutputFile(new File("c:/chartest.xml"));
  XsltTransformer trans = exp.load();
  
  trans.setInitialContextNode(source);
  trans.setDestination(out);
  trans.transform();
  }
  catch (SaxonApiException sae) {
   sae.printStackTrace();
  }
 }
 
}
 
 

I get this error message
 

net.sf.saxon.s9api.SaxonApiException: Cannot use character maps in an environment with no Controller

at net.sf.saxon.s9api.Serializer.getReceiver(Serializer.java:362)

at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:226)

at gov.irs.TFPOnlineProcessing.SimpleTrans.main(SimpleTrans.java:38)

Caused by: net.sf.saxon.trans.XPathException: Cannot use character maps in an environment with no Controller

at net.sf.saxon.event.SerializerFactory.getReceiver(SerializerFactory.java:114)

at net.sf.saxon.s9api.Serializer.getReceiver(Serializer.java:360)

... 2 more

 

Does anyone have any ideas on how to fix this?

 

Steve