Nila91
Nila91

Reputation: 17

XSL Replace with multiple values without duplications

I'm trying to filter and then replace umlauts in a file name. Unfortunately this doesn't really work, because if all three umlauts are included, the variable name is also written several times in the filename.

<xsl:choose>
<xsl:when test="contains($name,'ä') or contains($name,'ö') or contains($name,'ü')">
<xsl:value-of select="replace($name, 'ä', 'ae'),replace($name,'ö','oe'),replace($name, 'ü', 'ue') " />
</xsl:when>

No matter what I try, either it just replaces an umlaut, or I have multiple times the filename after the transformation. When I try to create a nested replace where the variable occurs only once, the file cannot be saved without errors.... Does anyone of you have an idea how I have only once the name in the filename, but all umlaut are replaced?

Upvotes: 0

Views: 87

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117102

Try:

<xsl:value-of select="replace(replace(replace($name, 'ä', 'ae'), 'ö', 'oe'), 'ü', 'ue')"/>

Alternatively, you could try something more generic, e.g.

<xsl:value-of select="replace(normalize-unicode($name, 'NFD'), '([aou])&#776;', '$1e')"/>

but here you need to carefully evaluate the possible effect on other diacritics that the input may contain.

Upvotes: 1

Related Questions