XSLT,如何获取和输出组合元素
亲爱的社区, 如果您能给我关于如何将其转换为的建议,那就太好了:
<div>
something
<title> this title </title>
something else
</div>
不幸的是
<div>
<title1>
something </title1>
<title2> this title </title2>
<title3> something else </title>
</div>
,无法使用 substring-before/after 方法,因为 div 中有一个内部元素。此外,复制似乎也不适用于子字符串。您对如何转换上述 xml 有什么建议吗?
Dear community,
it would be great if you could give me an advice on how to transform this:
<div>
something
<title> this title </title>
something else
</div>
into
<div>
<title1>
something </title1>
<title2> this title </title2>
<title3> something else </title>
</div>
Unfortunately the substring-before/after method cannot be used as there is an inner element inside div. Moreover, copy-of seems like it doesn't work with substring either. Do you have any advice on how to transform the above xml?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
该样式表:
输出:
This stylesheet:
Output:
这个解决方案同时更精确和更通用:
当应用于提供的 XML 文档时:
产生更接近所需的结果(仅 NL 或 CR 字符会转换为空格):
This solution is a little bit more precise and more general at the same time:
When applied on the provided XML document:
a more closer to the desired result is produced (only NL or CR characters are converted to space):
编辑
我刚刚意识到我的输出与你的不匹配。
但是@Alejandro的解决方案是完美的,所以我希望你不会对此感到太沮丧。
我想出了这个解决方案:
它产生以下输出:
Edit
I just realized that my output doesn't match yours.
But @Alejandro's solution is perfect, so I hope you won't be too upset about this one.
I came up with this solution:
which produces this output: