XSLT / XML:将撇号转换为特定的实体字符串
我希望能够使用 XSLT 将撇号转换为字符串 '
。我有以下 XML
<OrgName>King's College</OrgName>
我希望能够输出以下内容:
<OrgName>King's College</OrgName>
我尝试过字符映射表,但我认为这不起作用,因为您只能用字符串替换单个字符。
我也尝试过替换功能,但我不确定如何确保完整的字符串实际出现在输出文件中?
<xsl:value-of select='replace(OrgName,"&apos;","&apos;")' />
在我的最终解决方案中,我需要能够替换文本中的所有撇号,而不仅仅是一个节点。
I'd like to be able to convert an apostrophe to the string '
using XSLT. I've got the following XML
<OrgName>King's College</OrgName>
I'd like to be able to output the following:
<OrgName>King's College</OrgName>
I've tried a character map but I don't think this works as you can only replace a single character with a string.
I've also tried a replace function but I'm not sure what I can do to make sure that the full string actually appears in the output file?
<xsl:value-of select='replace(OrgName,"'","'")' />
In my final solution I need to be able to replace all apostrophe's in the text rather than just for one node.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用字符映射如下就这么简单:
当此转换应用于提供的 XML 文档时:
生成所需的正确结果:
Using a character map is as simple as this:
when this transformation is applied on the provided XML document:
the wanted, correct result is produced:
这只是部分答案:
要替换字符
'
,您可以使用以下内容:这需要 XSLT/XPath 2.0。说明
codepoints-to-string
从代码点序列返回一个字符串,39
对应于字符'
'用于执行此替换XML 的每个节点...我目前没有解决方案:会考虑一下。
无论如何,我希望这会有所帮助。
This is only a partial answer:
For replacing the character
'
you may use the following:which requires XSLT/XPath 2.0. Explanation
codepoints-to-string
returns a string from a sequence of code points, and39
corresponds to the character'
'For doing this replacement on every node of your XML ... I have no solution at the moment: will think about it.
Anyway, I hope this helps.