I am trying to translate names to display correctly in a database using xsl version 1.0 logic that have special characters, specifically umlauts. I have been able to get ö, ä, and ü to be translated to o,a,u respectively when they are part of the value being included under the field mapped in the xml.
I've been able to get that to work correctly with the first xsl block below but the Ampersand actually displays as & instead of & and it's only for a single name. How can I modify these two xsl examples into one so that both transformations display how intended. Everything I've tried to combine the two cases results in an xsl compile error.
End Goal: Have all names display correctly with replaced/translated values of o,u,a in place of umlauts and still display & correctly, not just for a single office value like Test & Welcome.
ex."Test & Welcöme" should display as "Test & Welcome"
- Works without xsl compile error but displays & instead of & Test results: Test & Welcome
<xsl:when test="ROF_NAME='Test & Welcme'">
<xsl:text>Test & Welcome</xsl:text><xsl:text>!~</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(ROF_NAME,1,149)" disable-output-escaping="yes"/><xsl:text>!~</xsl:text>
</xsl:otherwise>
</xsl:choose><xsl:text>!~</xsl:text>```
2. Uses unicode for umlaut values and no compile error but isn't actually translating the umlauts into plain characters but the ampersand does display correctly:
Output results: Test & Welcme
```<xsl:choose>
<xsl:when test="normalize-space(ROF_NAME) != ''">
<xsl:value-of select="substring(translate(ROF_NAME, 'öäü', 'oau'), 1, 149)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>!~</xsl:text>```
3.I also tried this but it gives an xslt compile error:
```<xsl:choose>
<xsl:when test="normalize-space(ROF_NAME) != ''">
<xsl:value-of select="substring(translate(ROF_NAME, 'öäü', 'oau'), 1, 149)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>!~</xsl:text>```
OVERALL I think 2 is the closest to what I want but it doesn't display the translated value
I am trying to translate names to display correctly in a database using xsl version 1.0 logic that have special characters, specifically umlauts. I have been able to get ö, ä, and ü to be translated to o,a,u respectively when they are part of the value being included under the field mapped in the xml.
I've been able to get that to work correctly with the first xsl block below but the Ampersand actually displays as & instead of & and it's only for a single name. How can I modify these two xsl examples into one so that both transformations display how intended. Everything I've tried to combine the two cases results in an xsl compile error.
End Goal: Have all names display correctly with replaced/translated values of o,u,a in place of umlauts and still display & correctly, not just for a single office value like Test & Welcome.
ex."Test & Welcöme" should display as "Test & Welcome"
- Works without xsl compile error but displays & instead of & Test results: Test & Welcome
<xsl:when test="ROF_NAME='Test & Welcme'">
<xsl:text>Test & Welcome</xsl:text><xsl:text>!~</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring(ROF_NAME,1,149)" disable-output-escaping="yes"/><xsl:text>!~</xsl:text>
</xsl:otherwise>
</xsl:choose><xsl:text>!~</xsl:text>```
2. Uses unicode for umlaut values and no compile error but isn't actually translating the umlauts into plain characters but the ampersand does display correctly:
Output results: Test & Welcme
```<xsl:choose>
<xsl:when test="normalize-space(ROF_NAME) != ''">
<xsl:value-of select="substring(translate(ROF_NAME, 'öäü', 'oau'), 1, 149)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>!~</xsl:text>```
3.I also tried this but it gives an xslt compile error:
```<xsl:choose>
<xsl:when test="normalize-space(ROF_NAME) != ''">
<xsl:value-of select="substring(translate(ROF_NAME, 'öäü', 'oau'), 1, 149)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:text> </xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>!~</xsl:text>```
OVERALL I think 2 is the closest to what I want but it doesn't display the translated value
Share
Improve this question
asked Mar 17 at 14:54
flea02flea02
91 bronze badge
16
|
Show 11 more comments
1 Answer
Reset to default 0End Goal: Have all names display correctly with replaced/translated values of o,u,a in place of umlauts and still display & correctly
Here is a simple example:
XML input:
<root>
<name>Test</name>
<name>Test & Welcome</name>
<name>Welcöme</name>
<name>Test & Welcöme</name>
</root>
XSLT:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3./1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="name">
<xsl:copy>
<xsl:value-of select="translate(., 'öäü', 'oau')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
The result here will be:
<?xml version="1.0"?>
<root>
<name>Test</name>
<name>Test & Welcome</name>
<name>Welcome</name>
<name>Test & Welcome</name>
</root>
which meets both your requirements of (1) removing the umlauts and (2) displaying the ampersand correctly (as required by the XML specification).
text
orxml
orhtml
? Is the XSLT processor in charge of serialization? What are you trying to achieve withdisable-output-escaping="yes"
? – Martin Honnen Commented Mar 17 at 15:10