-1

I need to remove the following characters from a string value using xsl 1.0:

`, / *` and break line (**<br>**)

I have come up with the following:

<xsl:value-of select="translate(//string/string/string/string, translate(//string/string/string/string, ',/*<br>'" ', ''), '')" />

But it's not working well, what or where should I look to change? Thanks

Mathias Müller
  • 22,203
  • 13
  • 58
  • 75
ofer_e
  • 27
  • 1
  • 8
  • 1
    Can you be a bit more specific rather than just saying "It's not working well"? i.e Are you getting an error message? Ideally you should show a sample of your input XML, a sample of your expected output, and the output you are actually getting. Thanks! – Tim C Feb 04 '15 at 13:19

1 Answers1

0

Firstly always break down problems into smaller subsets.

the function translate is basically a character-level operation. as such it is not suitable for the <br> part of the solution. Also note that < and > are special characters in xsl/xml.

Thus, assuming //string/string/string/string IS the correct XPath here..

translate(//string/string/string/string, ',/*','   '):

Should be sufficient to remove the , and / and * characters

As for <br>, well ideally you'd want to use a replace function, which does not exist in xslt 1.0. Take a look at this question for an example of a template which does the job if you are in xslt 1: XSLT string replace

you could also consider if xslt is the right tool for the job here, but that depends on the wider context.

Community
  • 1
  • 1
tolanj
  • 3,651
  • 16
  • 30
  • 1
    If the characters in the second argument to `translate` are to be removed then the third argument should be an empty string `''` and not `' '` as that would replace the characters with a blank. – Martin Honnen Feb 04 '15 at 14:14
  • Perhaps you could say more explicitly that an unescaped `
    ` cannot be part of a string in XML? And, by extension, that using regexes to find and remove elements is a bad idea?
    – Mathias Müller Feb 04 '15 at 14:41