xml charset translation with xsl

R

reynard.michel

Hi,
I would like to translate an XML ISO-8859-1 document in UTF-8.
For this I wrote the following XSL

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

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

It works fine except that it does not keep the atributes.
How can I do a translation with the attributes?

Further more I've some permil il the xml. If they are written as &
permil; they get translated in a permil char but if they are written as
& #2030; which is the permil char in ISO-8859-1 it is transformed in an
unknown char. How can I do a traslate from & #2030 to & #8240; (utf-8
permil) or to a permil char?

Thank you for your help

Michel
 
J

Johannes Koch

Hi,
I would like to translate an XML ISO-8859-1 document in UTF-8.
For this I wrote the following XSL

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

<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

It works fine except that it does not keep the atributes.
How can I do a translation with the attributes?

See the XSLT spec for the identity template
( said:
Further more I've some permil il the xml. If they are written as &
permil; they get translated in a permil char but if they are written as
& #2030; which is the permil char in ISO-8859-1

No, it's not. The XHTML character entity reference &permil; is ‰
or (hex) ‰. Note the 'x'.
 
G

George Bina

That is not an identity transformation, you can use something like
below and delete your current template:

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

to get the same contyent to the output.

If you want to convert some character to another then you can add a
rule matching text nodes and output the value of the text node through
the translate function that converts your character in the initial
document to the desired character in the output.

Best Regards,
George
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top