简体   繁体   English

如何在 XSL 中将字符串的一部分替换为不同的字符

[英]How to replace a part of a string to a different character in XSL

I'm new to XSLT and coding in general.我是 XSLT 和一般编码的新手。 However, I have to fix my codes so I can provide the correct output.但是,我必须修复我的代码,以便提供正确的 output。

Basically, some strings/values that I'm trying to produce in XSL contains a comma "," but I can't have that because my output file is going to be CSV.基本上,我试图在 XSL 中生成的一些字符串/值包含一个逗号“”,但我不能这样做,因为我的 output 文件将是 CSV。 so with the commas, it's going to mess up my output file.所以用逗号,它会弄乱我的 output 文件。 So I need to replace the commas in the string/values to an apostrophe "'".所以我需要将字符串/值中的逗号替换为撇号“'”。

Example of my lines below:下面是我的行示例:

<xsl:value-of select="replace(wd:HomeAddress/@wd:Descriptor),'[^a-zA-Z0-9]',''"/> <xsl:value-of select="replace(wd:HomeAddress/@wd:Descriptor),'[^a-zA-Z0-9]',''"/>

just got the above from random searches in google before I finally ended up here.在我最终来到这里之前,刚刚从谷歌的随机搜索中得到了上述内容。

Use translate:使用翻译:

<xsl:value-of select="Translate(wd:HomeAddress/@wd:Descriptor,',','''')"/>

This is simple function to change characters by others这是简单的 function 来改变别人的字符

EDIT: corrected the delimiters.编辑:更正了分隔符。

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

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