开发者

XSLT 2.0 replace function returns same string when comparing special html characters

I am writing an XSLT to produce HTML for HTML Help Viewer 1.0. Some of the titles contain the < and > sequences. This causes loads of problems with the viewer as it converts them back to angle brackets. Having read on-line that having them as there Unicode versions will work (http://mshcmigrate.helpmvp.com/faq/notes10) I tried to use the replace function to do this and the result is the same as the input.

The code I am using is:

replace(replace(/*/name, '<', '<'), '>', '>')

The input:

DocumentationTest.GenericClass<T> Namespace

Outputs as:

DocumentationTest.GenericClass<T> Namespace

How can I perform a string replace to get this output?

DocumentationT开发者_C百科est.GenericClass<T> Namespace


< and < are two different representations of the same character. You can use replace() (or more simply, translate()) to change one character to another, but you can't use it to control how that character is represented in the serialized output - that's entirely up to the serializer. You can influence it, however, using character maps - see xsl:character-map.


This is correct behavior as per the XML parser itself, which executes before XSLT gets ahold of it. If you must maintain the < in the document, then it should be encoded as <, and a simple find and replace on all & symbols, replacing them with &, should do the trick.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜