Re: [xsl] Character conversion in stylesheet

Subject: Re: [xsl] Character conversion in stylesheet
From: Michael Müller-Hillebrand <info@xxxxxxxxxxxxx>
Date: Fri, 2 Jul 2004 09:49:19 +0200
On 01.07.2004 (14:34 Uhr -0500), Belkin, Alla wrote:

>Hello,
>I have to check if I have some of the extended ASCII (UTF8) characters in the input XML file.
>So, I am using stylesheet for transformation XML input file to the different format of the XML file.
>Can I do something efficient to check for special characters in some of the fields in the input XML file and to convert those specific characters, (for example, è to e) in the output file?

To check if you have non-ASCII characters you can remove all ASCII chars from a string and check whether the result is empty. First create a string variable which contains all valid characters:

<xsl:variable name="ascii-chars">&#32;!...01234568789..ABCD...abcd...</xsl:variable>

For the test you would use the translate() function:

<xsl:if test="translate(., $ascii-chars, '') = ''">
...
</xsl:if>

To change non-ASCII chars to ASCII chars you have to know which characters to change. This is easy if you know the input is ISO-8859-1 or some other limited range of characters. You would use the translate() function.

If any valid UTF-8 char could be in the input, there is no easy solution, because in many languages single characters can only be transliterated to more than one ASCII character.

- Michael
--
________________________________________________________________
Michael Müller-Hillebrand, Dipl.-Ing.    <http://cap-studio.de/>
    FrameMaker, FrameScript, XML/XSL,... Publishing-Lösungen

Current Thread