仅通过 XSLT 从 XML 中删除特定标签的特殊字符
我的 XML 中存在特殊字符的问题。 基本上,我使用 Xalan Processor 将一个 xml 拆分为多个 xml。
当分割文档时,我使用它们的名称标签的值作为生成的文件的名称。问题在于该名称包含 XML 处理器无法识别的字符,例如 ™ (TM) 和 ® (R)。我只想在命名文件时删除这些字符。
<xsl:template match="products">
<redirect:write select="concat('..\\xml\\product\\en\\',translate(string(name),'</> ',''),'.xml')">
上面是我编写的用于将 XML 拆分为多个 XML 的 XSL 代码。正如你所看到的,我正在使用 hte 翻译方法来替换 '/','<','>'名称中带有“”。我希望我可以对 ™ (TM) 和 ® (R) 做同样的事情,但它似乎不起作用。 请告诉我如何才能做到这一点。
感谢您提前提供帮助。
I am having a certian issue with special characters in my XML.
Bascially I am splitting up an xml into multiple xmls using Xalan Processor.
When splitting the documents up I am using their value of the name tag as the name of the file generated. The problem is that the name contains characters that arent recognized by the XML processor like ™ (TM) and ® (R). I want to remove those characters ONLY when naming the files.
<xsl:template match="products">
<redirect:write select="concat('..\\xml\\product\\en\\',translate(string(name),'</> ',''),'.xml')">
The above is the XSL code I have writter to split the XML into multlpe XMLs. As you can see I am using hte translate method to subtitute '/','<','>' with '' from the name. I was hoping I could do the same with ™ (TM) and ® (R) but it doesnt seem to work.
Please advice me how I would be able to do that.
Thanks for you help in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有 Xalan,但使用 8 个其他 XSLT 处理器,此转换:
应用于此 XML 文档时:
产生所需的结果:
< strong>我建议您尝试使用上面两个表达式之一——至少第二个可能会成功。
I don't have Xalan, but with 8 other XSLT processors this thransformation:
when applied on this XML document:
produces the wanted result:
I suggest that you try to use one of the two expressions above -- at least the second may work successfully.
根据 Dimitre 的回答,我认为如果您不确定
name
中可能包含哪些特殊字符,也许您应该保留您认为的法律文档名称字符。例如:
输入:
结果:
Following Dimitre answer, I think that if you are not sure about wich special character could be in
name
, maybe you should keep what you consider legal document's name characters.As example:
With input:
Result: