Project

Profile

Help

Not convert entities

Added by Anonymous over 14 years ago

Legacy ID: #8534883 Legacy Poster: globozineu (globozineu)

Hello, We are using the Saxon library in order to convert xml files using an xslt template. In my xslt template, I have some entities, like [b]°[/b], but after the transformation, this one is converted as °. I would like to keep the entity as its initial value [b]°[/b], is that possible ? My method : [code] public static void xsltRun(File xmlIn, File xmlOut, File xsltF) throws Exception { try { Processor proc = new Processor(false); XsltCompiler compile = proc.newXsltCompiler(); StreamSource xslt = new StreamSource(xsltF); StreamSource source = new StreamSource(xmlIn); XsltExecutable xsltExe = compile.compile(xslt); net.sf.saxon.s9api.XsltTransformer trans = xsltExe.load(); Document doc = DOMUtils.createDocument(); DOMDestination dest = new DOMDestination(doc); trans.setSource(source); trans.setDestination(dest); trans.transform(); DOMXMLFragment xmlFrag = new DOMXMLFragment(doc); xmlFrag.save(xmlOut); } catch (Exception e) { throw new Exception("ERROR During XSL Transformation", e); } } [/code]


Replies (1)

RE: Not convert entities - Added by Anonymous over 14 years ago

Legacy ID: #8536670 Legacy Poster: Michael Kay (mhkay)

The short answer is no: the XML parser expands the entity reference, so the XSLT processor never gets to know that there was an entity reference there in the first place. However, a solution (or you might say a workaround) is available in a tool called LexEv from Andrew Welch, which converts the entity references into element nodes during parsing. You should be able to find it on google.

    (1-1/1)

    Please register to reply