admin管理员组文章数量:1435859
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).
本文标签:
版权声明:本文标题:xml - How to translate special characters using unicode and display & correctly in the same Choose block - Stack Overflo 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744552885a2612289.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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