Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do we render accent char without any encoding

My input has accent characterslike Í,Â,Ç Á, using xslt version 1.0 I need to render those characters without any change.

For example : input Í ÇÂME HOME output Í ÇÂME HOME I dont want to encode/change those accent characters but I am getting output like Ã? ÇÂME HOME

What I have observed is: Í is converting to Ã? Ç to Ç  to Â

If you observe all these characters are converting to capital a, tilde with additional chars(, ? ‡ )

Can anyone Please help me My style sheet looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
    <xsl:template match="/">

        <xsl:element name="root">
                      <xsl:value-of select="/../inputpath/msg"/>
                <\xsl:element>
</xsl:stylesheet>

Code used to transform xml

public static String transformByXslt(final String input, final String styleSheet,
            final Map<String, String> parameterMap, final ProductMetadata productMetadata,
            final ProductInstance productInstance, final Map<String, Object> daoMap) throws TransformerException,
            UnsupportedEncodingException, ValidationException, NoNeedToRenderException {

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final TransformerFactory factory = TransformerFactory.newInstance();

        InputStream inputStream = null;

        inputStream = new ByteArrayInputStream(input.getBytes("UTF-8"));

        Transformer transformer = factory.newTransformer(new StreamSource(new ByteArrayInputStream(styleSheet
                .getBytes())));

        setParamsForXslt(transformer, parameterMap, productMetadata, productInstance, daoMap);
        transformer.setErrorListener(new PbErrorListener());
        try {
            transformer.transform(new StreamSource(inputStream), new StreamResult(out));
        } catch (TransformerException e) {
            if (ExceptionUtils.getRootCause(e) != null
                    && ExceptionUtils.getRootCause(e).getClass().equals(ValidationException.class)) {
                throw new ValidationException(e);
            } else if (ExceptionUtils.getRootCause(e) != null
                    && ExceptionUtils.getRootCause(e).getClass().equals(NoNeedToRenderException.class)) {
                throw new NoNeedToRenderException(e);
            } else if (ExceptionUtils.getRootCause(e) != null
                    && ExceptionUtils.getRootCause(e).getClass().equals(BlankRenditionException.class)) {
                return "";
            } else {
                throw e;
            }
        }

        return out.toString("UTF-8");
    }
like image 603
Rupesh Dasari Avatar asked Nov 04 '22 07:11

Rupesh Dasari


1 Answers

Rupesh, you are treating UTF-8 encoded data as signle-byte coded data or encoding UTF-8 twice. (the

out.toString("UTF-8") 

???)

First step is to figure out, what encoding is your data in and what encoding are you supposed to produce. For instance if you use Notepad++, it has a menu "Encoding" where it shows you the current encoding of the file and allows you to change it, see the effect. Tell us what's the story.

You might be after the western european windows ecoding: windows-1252

Check this as well: the encoding attribute of the XSL output element

I could give you some sample in C# if you like, but you run Java...

like image 61
Robert Cutajar Avatar answered Nov 14 '22 23:11

Robert Cutajar