I've got a XML document that I want to cop<, but I don't know how to translate one special attribute. Copying the XML and replacing the attribute in gernal works fine, but I don't know how I can define a list of phrases in XSL that are then translated into another phrase.
The definition should be easyly readable. Does translate()
swallow some kind of list representation? A small example using translate
would be great (don't care about the XML copying stuff).
The
translate
function of XPath and XSLT 1.0 serves only to replace one Unicode character by another Unicode character; you can provide a list of input and replacement characters where then each character in the first list is then replaced by the one in the second list at the same position. But to replace complete works or phrases you need other tools.You have not said or described whether you want to replace the complete attribute value, assuming that you can (with XSLT 2.0) simply do e.g.
That stylesheet transforms for instance
into
If you want to do several replacements of substrings in one value or string then more effort is needed but with the
replace
function in XSLT/XPath 2.0 that is possible too.[edit]Here is an example using a list of items and a recursive function replacing phrases:
That transforms the example
into