通过 XSLT 用 XHTML 中的标签替换 style= 属性
假设我在 XHTML 页面中有以下内容:
<span style="color:#555555; font-style:italic">some text</span>
我将如何将其转换为:
<span style="color:#555555;"><em>some text</em></span>
Say I have the following in an XHTML page:
<span style="color:#555555; font-style:italic">some text</span>
How would I go about transforming this to:
<span style="color:#555555;"><em>some text</em></span>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这并不像看起来那么容易,因为 XSLT 不是字符串解析的最佳工具 - 但这正是您一般情况下获取样式属性内容所需要的。
但是,根据您输入的复杂性,类似这样的内容可能就足够了(不过,我尝试尽可能通用):
This is not as easy as it seems since XSLT is not the best tool for string parsing - but that's exactly what you need to get the contents of the style attribute right generically.
However, depending on the complexity of your input, something like this might be enough (I tried to be as generic as possible, though):
只是为了好玩,更通用的 XSLT 2.0 解决方案(可以优化):
输出:
Just for fun, a more general XSLT 2.0 solutions (can be optimized):
Output: