How to replace a part of a string to a different character in XSL

Viewed 44

I'm new to XSLT and coding in general. However, I have to fix my codes so I can provide the correct 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. so with the commas, it's going to mess up my output file. 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]',''"/>

just got the above from random searches in google before I finally ended up here.

1 Answers

Use translate :

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

This is simple function to change characters by others

EDIT: corrected the delimiters .

Related