如何从 .xsl 文件中的 xml 文件获取所需的标记值?
我有以下类型的文件包含 xml 格式,
<?xml version="1.0" encoding="UTF-8"?>
<root>
<serviceImpl category="default">
<package>esterMemoryManagement</package>
<service singleton="true">
<provides>xoc.hw.cor.memgt.ZContentType</provides>
<brief>This sis first sdrevice</brief>
</service>
</serviceImpl>
<serviceImpl category="default">
<package>w.cor.TesterM</package>
<service singleton="true">
<provides>xoc.hw.ZAccessTypeProvid</provides>
<brief>This sis first sdrevice</brief>
</service>
</serviceImpl>
</root>
我必须获取 .xsl 文件中标记
内的所有值。我怎样才能做到这一点? 提前致谢。
I have following type of file contains in xml format
<?xml version="1.0" encoding="UTF-8"?>
<root>
<serviceImpl category="default">
<package>esterMemoryManagement</package>
<service singleton="true">
<provides>xoc.hw.cor.memgt.ZContentType</provides>
<brief>This sis first sdrevice</brief>
</service>
</serviceImpl>
<serviceImpl category="default">
<package>w.cor.TesterM</package>
<service singleton="true">
<provides>xoc.hw.ZAccessTypeProvid</provides>
<brief>This sis first sdrevice</brief>
</service>
</serviceImpl>
</root>
i have to get all values within tag <provides></provides>
in .xsl file. How can i do that?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这是一个简短而完整的解决方案:
当此转换应用于提供的 XML 文档时:
生成所需的正确结果:
说明:
生成结果的唯一模板是匹配
provides
的模板。第二个模板匹配任何文本节点并具有空正文,它有效地覆盖文本节点的 XSLT 内置模板并防止(“删除”)任何匹配的文本节点输出(否则将由 XSLT 内置模板执行的操作)。
Here is a short and complete solution:
when this transformation is applied on the provided XML document:
the wanted, correct result is produced:
Explanation:
The only template that produces the result is the one matching
provides
.The second template matches any text node and has an empty body, which effectively overrides the XSLT built-in template for text nodes and prevents ("deletes") any matched text node from being output (an action that otherwise would have been performed by the XSLT built-in template).
这是一种方法:
您可能还想查看 这个问题,以及相关答案。
Here's one way of doing it:
You may also want to have a look at this question, and related answers.
您可以使用 XSL 过滤掉如下值:(
顺便说一句,您的示例 XML 并非在所有地方都正确)
You can use XSL to filter out values like:
(btw, Your example XML is not correct in all places)