title: Replace special characters like &ndash; and &mdash; occuring in an xml document with corresponding code like &#150; etc
body: <p>I wish to replace special characters like &amp; ndash; and &amp; mdash; occuring in an xml document with corresponding code like &amp; #150; etc</p>
  
  <p>i have an input xml document containing several special characters </p>
  
  <pre><code> &lt;?xml version="1.0"?&gt;
    &lt;!DOCTYPE BOOK SYSTEM "bookfull.dtd"&gt;
  &lt;BOOK&gt; 
    &lt;P&gt;The war was between1890&amp;ndash;1900
     &lt;AF&gt;something&amp;mdash;something else&lt;/AF&gt;
  &lt;/P&gt;
  &lt;/BOOK&gt;
  </code></pre>
  
  <p>there are several other characters like &amp; rsquo; for single quotation</p>
  
  <p>my xslt code is as follows</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt;
       &lt;xsl:stylesheet version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml"&gt;
  
  &lt;xsl:output method="html" omit-xml-declaration="yes" indent="yes" /&gt;
  &lt;xsl:strip-space elements="*" /&gt;
  
  
  &lt;xsl:param name="pDest"
      select="'file:///d:/LWW_Book_ePub_Transform/Epub_ZipCreation/XSLT_Transform/Output/'" /&gt;
  
  &lt;xsl:template-match="P"&gt;
  &lt;html&gt;
  &lt;xsl:apply-templates/&gt;
  &lt;/html&gt;
  &lt;/xsl:template-match&gt;
  
  &lt;xsl:template-match="AF"&gt;
  .....
  &lt;xsl:apply-templates/&gt;
  .....
  &lt;/xsl:template-match&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>my java codes for parsing is as follow (i am making use of saxon9.)</p>
  
  <pre><code>package com.xsltprocessor;
  
  import java.io.File;
  import java.io.FileInputStream;
  import javax.xml.parsers.DocumentBuilder;
  import javax.xml.parsers.DocumentBuilderFactory;
  import javax.xml.transform.Source;
  import javax.xml.transform.Templates;
  import javax.xml.transform.Transformer;
  import javax.xml.transform.TransformerFactory;
  import javax.xml.transform.stream.StreamResult;
  import javax.xml.transform.stream.StreamSource;
  
  import org.w3c.dom.Document;
  
  public class ParseUsingSAX {
  
  public ParseUsingSAX() {
  }
  
  public void parseBookContent(String xsltFile) {
      try {
  
  
          //File inputXml = new File("D:\\data\\myxml.0f");
          File xslt = new File(xsltFile);
  
          TransformerFactory factory = TransformerFactory.newInstance();
          Templates template = factory.newTemplates(new StreamSource(new FileInputStream(xslt)));
          Transformer xformer = template.newTransformer();
          Source source = new StreamSource(new FileInputStream(inputXml));
          StreamResult result = new StreamResult();
          xformer.transform(source,result);           
          System.out.println("DONE");
      }
      catch (Exception ex) {
          // TODO Auto-generated catch block
          ex.printStackTrace();
          System.out.println("IO exception: " + ex.getMessage());
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>i am getting the output after transformation as</p>
  
  <pre><code>&lt;html&gt;
  The war was between1890&amp;ndash;1900
  &lt;/html&gt;
  </code></pre>
  
  <p>expected output</p>
  
  <pre><code>&lt;html&gt;
  The war was between1890&amp;#150;1900
  &lt;/html&gt;
  </code></pre>