質問

I'm trying to translate some Strings in XPath but I'm getting some weird outputs.

That's the function:

translate(translate(translate(translate('1 day 23 hours 30 minutes 25 seconds','day','dag'),'hours','uur'),'minutes','minuut'),'seconds','seconden')

And the currently output is:

1 dag 23 uur 30 minrut 25 tcund 

But what I need is: 1 dag 23 uur 30 minuut 25 seconden

Is there any special way of translating multiple substrings at once?

役に立ちましたか?

解決

That's not how translate() works. When you translate:

translate('minutes seconds','hours','uur')

the expected result is:

minrte ecund

because you are actually telling the processor to replace the occurrences of the first three letters in the second argument:

'h', 'o', 'u'

as they occur in the string 'minutes seconds' with the corresponding characters

'u', 'u', 'r'

respectively, and remove the characters 'r' and 's', since they have no corresponding replacements in the third argument.

If you want to replace full words, and are using XPath 2.0, then you can use the replace() function.

replace(replace(replace(replace('1 day 23 hours 30 minutes 25 seconds','day','dag'),'hours','uur'),'minutes','minuut'),'seconds','seconden')
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top