Search code examples
xsltxslt-1.0transformxslt-2.0

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?


Solution

  • 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.