1

I'm trying to come up with a good way of replacing special characters such as ã, û, ü etc with their base alphabet in BizTalk. Currently I'm using the following XSL form:

<xsl:template match="text()">
    <xsl:call-template name="ReplaceChars">
        <xsl:with-param name="Input" select="."></xsl:with-param>
    </xsl:call-template>
</xsl:template>

<xsl:variable name="OddChars">ÄÖÅÜÉäöåüé</xsl:variable>
<xsl:variable name="RegChars">AOAUEaoaue</xsl:variable>

<!-- Replaces odd characters with regular ones  -->
<xsl:template name="ReplaceChars">
    <xsl:param name="Input" />
    <xsl:value-of select="translate($Input, $OddChars, $RegChars)"/>
</xsl:template>

The above is working just fine. My question is this: is there a better or "smarter" way of doing this? I can't find anything sensible with google. I was thinking using .Net inline code of simply forcing another culture on the text, to automatically strip the special signs from the base characters. But I can't seem to get that working either.

Basically, I don't want to create an app where you'd have to constantly update the character list and risk a new special character that isn't defined, getting through and causing errors on the receiving app. But do I have a choice?

Kahn
  • 1,630
  • 1
  • 13
  • 23
  • You could consider using `msxsl:script` to embed C# or VB code inplementing an extension function with code like presented in http://stackoverflow.com/questions/3769457/how-can-i-remove-accents-on-a-string. But it all depends on whether your needs or your definition of "special characters" and their replacement matches the one used in that answer. – Martin Honnen Apr 16 '12 at 10:42
  • There isn't a "smarter way", because you haven't provided a definition of what a "special character" is, nor of how its replacement should be generated. In fact, different languages may have different rules for the replacement of the same character, as pointed by @msam. One way to make this code more flexible is to place the set of all "special characters" and their corresponding "replacements" into a separate XML file. In this way the code will never have to be modified. – Dimitre Novatchev Apr 16 '12 at 12:26

2 Answers2

2

another alternative would be to use regular expressions to replace the characters you want.

More importantly you do realize that mapping characters in this way could cause some confusion right? For example Germanic languages map ä to ae, ü to ue and ö to oe and mapping to a, u and o will change the meaning of some words.

msam
  • 4,259
  • 3
  • 19
  • 32
  • Yes I'm aware of the drawbacks, the source and destination systems are out of my control. Furthermore, there are some constraint checks such as string length etc that are decided and checked on the source system so using a solution that could replace ä with ae for instance might produce errors, and therefore is not an option either. Still, thanks for the response. :) – Kahn Apr 17 '12 at 10:37
0

My question is this: is there a better or "smarter" way of doing this?

...

Basically, I don't want to create an app where you'd have to constantly update the character list and risk a new special character that isn't defined, getting through and causing errors on the receiving app. But do I have a choice?

There isn't a "smarter way", because you haven't provided a definition of what a "special character" is, nor of how its replacement should be generated.

In fact, different languages may have different rules for the replacement of the same character, as pointed by @msam.

One way to make this code more flexible is to place the set of all "special characters" and their corresponding "replacements" into a separate XML file. In this way the code will never have to be modified.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431