简体   繁体   English

XSL 用字符串替换特殊字符

[英]XSL replace special character by a String

I am new to XSL and I have the following XML node that I need to parse to regular text:我是 XSL 的新手,我有以下 XML 节点,我需要将其解析为常规文本:

<GeneralRemark Source="A3" SourceRef="LD8PN5">
    <ElementNumber Source="A3" SourceElement="14">9</ElementNumber>
    <Text>SPECIAL CHARACTER € EURO SIGN</Text>
</GeneralRemark>

I need to read the data in text node, and in the output replace € by EUR.我需要读取文本节点中的数据,并在 output 中用 EUR 替换 €。 My app does not support €, so I can't use it.我的应用不支持€,所以我不能使用它。

This is how I am reading the GeneralRemark node now:这就是我现在阅读 GeneralRemark 节点的方式:

<xsl:if test="../PNRViewRS/GeneralRemark/Text">
    <xsl:for-each select="../PNRViewRS/GeneralRemark/Text">
        <xsl:text>RM </xsl:text>
        <xsl:value-of select="."/>                  
        <xsl:value-of select="$cr"/>                        
    </xsl:for-each>
</xsl:if>

Any tips on how to approach this will be appreciated.任何有关如何解决此问题的提示将不胜感激。

If the text always contains exactly one occurrence of the pattern you want to replace, you could use:如果文本总是包含您要替换的模式的一个匹配项,您可以使用:

<xsl:value-of select="substring-before(., '€')"/> 
<xsl:text>EUR</xsl:text>                 
<xsl:value-of select="substring-after(., '€')"/> 

Otherwise you will need to call a named recursive template to replace all possible occurrences of the pattern.否则,您将需要调用命名递归模板来替换所有可能出现的模式。 See an example here: https://stackoverflow.com/a/30339654/3016153在此处查看示例: https://stackoverflow.com/a/30339654/3016153

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM